Skip to main content

cellix_term/
lib.rs

1//! Terminal side of Cellix: choosing a rendering tier and presenting grids.
2
3mod cells;
4mod detect;
5mod pixels;
6mod probe;
7
8pub use cells::CellBackend;
9pub use detect::{background, detect};
10pub use pixels::{Bleed, DEFAULT_QUOTA, PixelBackend, Placement, Smooth, row_key};
11pub use probe::{Env, Multiplexer, Tier, select_tier};
12
13use std::io::{self, Write};
14use std::time::{Duration, Instant};
15
16use cellix_render::{Grid, Rect};
17
18/// Presents a grid. Implementations send only what changed since the last call.
19pub trait Backend {
20    fn present(&mut self, grid: &Grid, out: &mut dyn Write) -> io::Result<()>;
21
22    /// Starts moving `area` from one grid to the other, `rows` lines further down the content,
23    /// or up if negative, and carries on from where it is if it's already moving. The moving
24    /// happens in `glide`. Tiers that can't move
25    /// anything by less than a cell do nothing, and the page just jumps.
26    fn scroll(
27        &mut self,
28        _from: &Grid,
29        _to: &Grid,
30        _area: Rect,
31        _rows: i32,
32        _out: &mut dyn Write,
33    ) -> io::Result<()> {
34        Ok(())
35    }
36
37    /// How often a scroll under way wants to move, if there is one.
38    fn gliding(&self) -> Option<Duration> {
39        None
40    }
41
42    /// Moves a scroll under way one step on.
43    fn glide(&mut self, _now: Instant, _out: &mut dyn Write) -> io::Result<()> {
44        Ok(())
45    }
46
47    /// Ends a scroll under way, for the next present to show the page as it is.
48    fn settle(&mut self) {}
49
50    /// Forgets what the terminal shows, so the next present redraws everything.
51    fn invalidate(&mut self);
52}