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