Skip to main content

katui_present/
lib.rs

1//! Presenters: the only place that produces bytes. A presenter consumes a
2//! scene diff and writes to a [`Sink`], which is stdout, a buffer, a
3//! socket or a test harness.
4
5mod anchor;
6pub mod blocks;
7pub mod cells;
8pub mod kitty;
9pub mod select;
10pub mod session;
11pub mod surface;
12
13/// Where a presenter writes its output; every writer is a sink.
14pub trait Sink: std::io::Write {}
15
16impl<T: std::io::Write> Sink for T {}
17
18#[cfg(test)]
19mod tests {
20    use super::Sink;
21
22    fn write_greeting(sink: &mut dyn Sink) -> std::io::Result<()> {
23        sink.write_all(b"\x1b_Ga=q\x1b\\")
24    }
25
26    #[test]
27    fn any_writer_is_a_sink() {
28        let mut buffer: Vec<u8> = Vec::new();
29        write_greeting(&mut buffer).expect("writing to a Vec cannot fail");
30        assert_eq!(buffer, b"\x1b_Ga=q\x1b\\");
31    }
32}