diff options
Diffstat (limited to 'src/state')
| -rw-r--r-- | src/state/mod.rs | 4 | ||||
| -rw-r--r-- | src/state/threads.rs | 29 |
2 files changed, 26 insertions, 7 deletions
diff --git a/src/state/mod.rs b/src/state/mod.rs index fc563e7..5313b4f 100644 --- a/src/state/mod.rs +++ b/src/state/mod.rs @@ -2,6 +2,6 @@ mod threads; pub use threads::Threads; -pub enum State<'d, 'q> { - Threads(Threads<'d, 'q>), +pub enum State { + Threads(Threads), } diff --git a/src/state/threads.rs b/src/state/threads.rs index 20b365e..f3d8721 100644 --- a/src/state/threads.rs +++ b/src/state/threads.rs @@ -3,17 +3,36 @@ use super::State; use std::io::Write; use termion::{color, event::Key}; -pub struct Threads<'d, 'q> { - pub threads: Vec<notmuch::Thread<'d, 'q>>, +pub struct Threads { + pub threads: Vec<Thread>, pub i: isize, } -impl<'d, 'q> Threads<'d, 'q> { +pub struct Thread { + subject: String, + authors: Vec<String>, + id: String, +} + +impl<'d, 'q> Threads { + pub fn new(threads: notmuch::Threads<'d, 'q>) -> Self { + let threads = threads.map(|t| Thread { + subject: t.subject().to_string(), + authors: t.authors().clone(), + id: t.id().to_string(), + }).collect(); + + Self { + threads, + i: 0 + } + } + pub fn init<W: Write>(&mut self, out: &mut W) { draw(&self, out); } - pub fn tick<W: Write>(mut self, out: &mut W, key: Key) -> State<'d, 'q> { + pub fn tick<W: Write>(mut self, out: &mut W, key: Key) -> State { match key { Key::Char('j') => self.i += 1, Key::Char('k') => self.i -= 1, @@ -34,7 +53,7 @@ fn draw<W: Write>(state: &Threads, out: &mut W) { if highlight { write!(out, "{}", color::Fg(color::Red)).unwrap(); } - write!(out, "thread {:?}, {:?}", thread.subject(), thread.authors()).unwrap(); + write!(out, "thread {:?}, {:?}", thread.subject, thread.authors).unwrap(); if highlight { write!(out, "{}", color::Fg(color::Reset)).unwrap(); } |
