diff options
| author | Gustav Sörnäs <gustav@sornas.net> | 2021-05-02 22:53:30 +0200 |
|---|---|---|
| committer | Gustav Sörnäs <gustav@sornas.net> | 2021-05-02 22:53:30 +0200 |
| commit | 9e393263e820c328355ac58584ac635540ef2e6b (patch) | |
| tree | 1dcb48b87c5f919afc1408bd5b508ba17c0a2ecc /src/window.rs | |
| parent | ea012211b6ad4d6973504b334816c568af9e60f3 (diff) | |
| download | mail-9e393263e820c328355ac58584ac635540ef2e6b.tar.gz | |
add basic window abstraction
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(()) + } +} |
