diff options
Diffstat (limited to 'src/window.rs')
| -rw-r--r-- | src/window.rs | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/window.rs b/src/window.rs new file mode 100644 index 0000000..178c484 --- /dev/null +++ b/src/window.rs @@ -0,0 +1,43 @@ +//! A window is an abstraction for the UI. Buffers (like [Threads]) draw "to" windows. + +use std::io::Write; +use termion::{clear, color, cursor}; + +pub enum Line { + Normal(String), + Highlight(String), +} + +pub struct Window { + pub lines: Vec<Line>, +} + +impl Window { + pub fn new() -> Self { + Self { + lines: Vec::new(), + } + } + + pub fn draw<W: Write>(&mut self, out: &mut W) -> Result<(), std::io::Error> { + write!(out, "{}", clear::All)?; + + for (i, line) in self.lines.iter().enumerate() { + write!(out, "{}", cursor::Goto(1, (i + 1) as u16))?; + match line { + Line::Normal(s) => write!(out, "{}", s)?, + Line::Highlight(s) => write!( + out, + "{}{}{}", + color::Fg(color::Red), + s, + color::Fg(color::Reset), + )?, + } + } + out.flush()?; + + self.lines.clear(); + Ok(()) + } +} |
