katui-present 0.0.3

Presenters: scene diffs translated into terminal bytes on a sink
Documentation
//! Presenters: the only place that produces bytes. A presenter consumes a
//! scene diff and writes to a [`Sink`], which is stdout, a buffer, a
//! socket or a test harness.

mod anchor;
pub mod blocks;
pub mod cells;
pub mod kitty;
pub mod select;
pub mod session;
pub mod surface;

/// Where a presenter writes its output; every writer is a sink.
pub trait Sink: std::io::Write {}

impl<T: std::io::Write> Sink for T {}

#[cfg(test)]
mod tests {
    use super::Sink;

    fn write_greeting(sink: &mut dyn Sink) -> std::io::Result<()> {
        sink.write_all(b"\x1b_Ga=q\x1b\\")
    }

    #[test]
    fn any_writer_is_a_sink() {
        let mut buffer: Vec<u8> = Vec::new();
        write_greeting(&mut buffer).expect("writing to a Vec cannot fail");
        assert_eq!(buffer, b"\x1b_Ga=q\x1b\\");
    }
}