aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGustav Sörnäs <gustav@sornas.net>2021-05-03 22:57:49 +0200
committerGustav Sörnäs <gustav@sornas.net>2021-05-03 22:59:13 +0200
commitb0bf51b90bc233024f1b82bf3f050d26f677b935 (patch)
treebdf6a8684fbd443d9186472b91c7cda989fc1e9a
parentc36df73b1e3d3c7f2feeda16e79bbdb2e1a4f251 (diff)
downloadmail-b0bf51b90bc233024f1b82bf3f050d26f677b935.tar.gz
scroll window
Closes #3
-rw-r--r--src/buffer/threads.rs2
-rw-r--r--src/window.rs17
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;
+ }
+ }
}