Skip to main content

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 files;
7mod notify;
8mod pixels;
9mod probe;
10
11pub use cells::CellBackend;
12pub use detect::{background, cell_size, detect};
13pub use files::TileFiles;
14pub use notify::{Notice, sequence as notification, terminal_names};
15pub use pixels::{Bleed, DEFAULT_QUOTA, OwnRows, PixelBackend, Placement, Smooth, row_key};
16pub use probe::{Env, Multiplexer, Tier, select_tier};
17
18use std::io::{self, Write};
19use std::time::{Duration, Instant};
20
21use cellix_render::{Grid, Rect};
22
23/// What a backend did since it was last asked, for the counters `CELLIX_PROF` keeps.
24#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
25pub struct Work {
26    /// Tiles sent to the terminal.
27    pub tiles: u64,
28    /// Rows rasterized.
29    pub rows: u64,
30}
31
32/// Presents a grid. Implementations send only what changed since the last call.
33pub trait Backend {
34    fn present(&mut self, grid: &Grid, out: &mut dyn Write) -> io::Result<()>;
35
36    /// Starts moving `area` from one grid to the other, `rows` lines further down the content,
37    /// or up if negative, and carries on from where it is if it's already moving. The moving
38    /// happens in `glide`. Tiers that can't move
39    /// anything by less than a cell do nothing, and the page just jumps.
40    fn scroll(
41        &mut self,
42        _from: &Grid,
43        _to: &Grid,
44        _area: Rect,
45        _rows: i32,
46        _out: &mut dyn Write,
47    ) -> io::Result<()> {
48        Ok(())
49    }
50
51    /// How often a scroll under way wants to move, if there is one.
52    fn gliding(&self) -> Option<Duration> {
53        None
54    }
55
56    /// Moves a scroll under way one step on.
57    fn glide(&mut self, _now: Instant, _out: &mut dyn Write) -> io::Result<()> {
58        Ok(())
59    }
60
61    /// Ends a scroll under way, for the next present to show the page as it is.
62    fn settle(&mut self) {}
63
64    /// Forgets what the terminal shows, so the next present redraws everything.
65    fn invalidate(&mut self);
66
67    /// How many lines the terminal has. Only a backend whose rows aren't the terminal's
68    /// lines needs telling: it fills what's left under its last row.
69    fn set_lines(&mut self, _lines: u16) {}
70
71    /// How far below its own place each of the last `foot` rows of `rows` is drawn, in
72    /// pixels, the last of them last. Only a backend that stands its foot's rows apart in
73    /// what's under the sheets says anything: a press there is then on the row drawn where
74    /// it lands, which isn't the row that begins there.
75    fn foot_drops(&self, _rows: u16, _foot: u16) -> Vec<usize> {
76        Vec::new()
77    }
78
79    /// What it has done since it was last asked: tiles sent and rows rasterized.
80    fn take_work(&mut self) -> Work {
81        Work::default()
82    }
83}