diff options
Diffstat (limited to 'src/window.rs')
| -rw-r--r-- | src/window.rs | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/src/window.rs b/src/window.rs index f01cfe9..68fc258 100644 --- a/src/window.rs +++ b/src/window.rs @@ -1,7 +1,7 @@ //! A window is an abstraction for the UI. Buffers (like [Threads]) draw "to" windows. use std::io::Write; -use termion::{clear, color, cursor}; +use termion::{color, cursor}; #[derive(Clone, Copy)] pub struct Area { @@ -18,18 +18,20 @@ pub enum Line { pub struct Window { pub lines: Vec<Line>, + scroll: usize, } impl Window { pub fn new() -> Self { Self { lines: Vec::new(), + scroll: 0, } } pub fn draw<W: Write>(&mut self, out: &mut W, area: Area) -> Result<(), std::io::Error> { let mut y = area.y; - let mut lines = self.lines.iter(); + let mut lines = self.lines.iter().skip(self.scroll); while y < area.h + 1 { match lines.next() { Some(line) => { @@ -54,4 +56,15 @@ impl Window { self.lines.clear(); Ok(()) } + + pub fn scroll_down(&mut self) { + //TODO check if we're at bottom + self.scroll += 1; + } + + pub fn scroll_up(&mut self) { + if self.scroll != 0 { + self.scroll -= 1; + } + } } |
