From b0bf51b90bc233024f1b82bf3f050d26f677b935 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Mon, 3 May 2021 22:57:49 +0200 Subject: scroll window Closes #3 --- src/buffer/threads.rs | 2 ++ 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, + scroll: usize, } impl Window { pub fn new() -> Self { Self { lines: Vec::new(), + scroll: 0, } } pub fn draw(&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; + } + } } -- cgit v1.2.1