diff options
| -rw-r--r-- | src/buffer/threads.rs | 2 | ||||
| -rw-r--r-- | src/window.rs | 17 |
2 files changed, 17 insertions, 2 deletions
diff --git a/src/buffer/threads.rs b/src/buffer/threads.rs index 49d9924..893b4ec 100644 --- a/src/buffer/threads.rs +++ b/src/buffer/threads.rs @@ -92,6 +92,8 @@ impl Threads { } else { self.i - 1 }, + Key::Char('e') => window.scroll_down(), + Key::Char('y') => window.scroll_up(), Key::Char('i') => { self.threads[self.i].remove_tag("inbox"); self.i += 1; 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; + } + } } |
