diff options
| author | Gustav Sörnäs <gustav@sornas.net> | 2021-04-28 22:47:15 +0200 |
|---|---|---|
| committer | Gustav Sörnäs <gustav@sornas.net> | 2021-04-28 22:47:15 +0200 |
| commit | 76d6819994201a776c6be18193018a2eb0a42415 (patch) | |
| tree | 8c509ce6239d4aa2878cde6230865b29f180e35c /src/state/threads.rs | |
| parent | abecc3b586a1d955fb0b1fe8c03132f755c559c3 (diff) | |
| download | mail-76d6819994201a776c6be18193018a2eb0a42415.tar.gz | |
only open db for as long as necessary
Diffstat (limited to 'src/state/threads.rs')
| -rw-r--r-- | src/state/threads.rs | 29 |
1 files changed, 24 insertions, 5 deletions
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(); } |
