aboutsummaryrefslogtreecommitdiffstats
path: root/src/buffer/threads.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/buffer/threads.rs')
-rw-r--r--src/buffer/threads.rs41
1 files changed, 17 insertions, 24 deletions
diff --git a/src/buffer/threads.rs b/src/buffer/threads.rs
index 85ffb0f..3525c2a 100644
--- a/src/buffer/threads.rs
+++ b/src/buffer/threads.rs
@@ -1,9 +1,9 @@
use crate::db;
+use crate::window::{Line, Window};
use super::Buffer;
use notmuch::DatabaseMode;
-use std::io::Write;
-use termion::{color, event::Key};
+use termion::event::Key;
pub struct Threads {
threads: Vec<Thread>,
@@ -68,11 +68,21 @@ impl Threads {
.collect();
}
- pub fn init<W: Write>(&self, out: &mut W) {
- self.draw(out);
+ pub fn fill_window(&self, window: &mut Window) {
+ println!("filling");
+ for (i, thread) in self.threads.iter().enumerate() {
+ let s = format!("thread: \'{}\' {:?}", thread.subject, thread.authors);
+ window.lines.push(
+ if self.i == i {
+ Line::Highlight(s)
+ } else {
+ Line::Normal(s)
+ }
+ );
+ }
}
- pub fn tick<W: Write>(&mut self, out: &mut W, key: Key) -> Option<Buffer> {
+ pub fn tick(&mut self, window: &mut Window, key: Key) -> Option<Buffer> {
match key {
Key::Char('j') => self.i += 1,
Key::Char('k') => self.i =
@@ -87,7 +97,7 @@ impl Threads {
}
Key::Char('s') => {
let sent = Threads::from_query(String::from("tag:sent"));
- sent.init(out);
+ sent.fill_window(window);
return Some(Buffer::Threads(sent));
}
Key::Char('r') => self.reload(),
@@ -96,24 +106,7 @@ impl Threads {
if !self.threads.is_empty() {
self.i = self.i.rem_euclid(self.threads.len());
}
- self.draw(out);
+ self.fill_window(window);
None
}
-
- fn draw<W: Write>(&self, out: &mut W) {
- write!(out, "{}", termion::clear::All).unwrap();
-
- for (i, thread) in self.threads.iter().enumerate() {
- write!(out, "{}", termion::cursor::Goto(1, (i + 1) as u16)).unwrap();
- let highlight = i == self.i;
- if highlight {
- write!(out, "{}", color::Fg(color::Red)).unwrap();
- }
- write!(out, "thread {:?}, {:?}", thread.subject, thread.authors).unwrap();
- if highlight {
- write!(out, "{}", color::Fg(color::Reset)).unwrap();
- }
- }
- out.flush().unwrap();
- }
}