diff options
Diffstat (limited to 'src/window.rs')
| -rw-r--r-- | src/window.rs | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/src/window.rs b/src/window.rs index 809ac4d..66d25bf 100644 --- a/src/window.rs +++ b/src/window.rs @@ -27,6 +27,20 @@ pub fn truncate_dots(s: &str, to: usize) -> String { } } +pub struct Statusbar(String); + +impl Statusbar { + pub fn new(s: String) -> Self { + Self(s) + } + + pub fn draw<W: Write>(&self, buf: &mut W, area: Area) -> Result<(), std::io::Error> { + write!(buf, "{}", cursor::Goto(area.x, area.y))?; + write!(buf, "{}", truncate_dots(&self.0, area.w as usize))?; + Ok(()) + } +} + pub struct Window { pub lines: Vec<Line>, scroll: usize, @@ -40,18 +54,17 @@ impl Window { } } - pub fn draw<W: Write>(&mut self, out: &mut W, area: Area) -> Result<(), std::io::Error> { - let mut buffer = Vec::new(); + pub fn draw<W: Write>(&mut self, buf: &mut W, area: Area) -> Result<(), std::io::Error> { let mut y = area.y; let mut lines = self.lines.iter().skip(self.scroll); while y < area.h + 1 { match lines.next() { Some(line) => { - write!(buffer, "{}", cursor::Goto(area.x, y))?; + write!(buf, "{}", cursor::Goto(area.x, y))?; match line { - Line::Normal(s) => write!(buffer, "{}", truncate_dots(s, area.w as usize))?, + Line::Normal(s) => write!(buf, "{}", truncate_dots(s, area.w as usize))?, Line::Highlight(s) => write!( - buffer, + buf, "{}{}{}", color::Fg(color::Red), truncate_dots(s, area.w as usize), @@ -63,8 +76,6 @@ impl Window { None => break, } } - out.write(&buffer)?; - out.flush()?; self.lines.clear(); Ok(()) |
