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