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