diff options
| -rw-r--r-- | src/main.rs | 12 | ||||
| -rw-r--r-- | src/state/threads.rs | 39 |
2 files changed, 23 insertions, 28 deletions
diff --git a/src/main.rs b/src/main.rs index 3f71050..58c084e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,17 +15,7 @@ fn main() { // hide the cursor let mut screen = termion::cursor::HideCursor::from(screen); - let mut threads = { - // open database - let db = crate::db::open(notmuch::DatabaseMode::ReadOnly).unwrap(); - - // get threads - let query = db.create_query("tag:inbox").unwrap(); - let threads = query.search_threads().unwrap(); - - Threads::from_query(Some(String::from("tag:inbox")), threads) - }; - + let threads = Threads::from_query(String::from("tag:inbox")); threads.init(&mut screen); let client = Client::new(State::Threads(threads)); diff --git a/src/state/threads.rs b/src/state/threads.rs index b6fddbb..be566e5 100644 --- a/src/state/threads.rs +++ b/src/state/threads.rs @@ -9,7 +9,7 @@ pub struct Threads { threads: Vec<Thread>, i: usize, - query: Option<String>, + query: String, } pub struct Thread { @@ -42,29 +42,29 @@ impl<'d, 'q> Thread { } } -impl<'d, 'q> Threads { - pub fn from_query(query: Option<String>, threads: notmuch::Threads<'d, 'q>) -> Self { - Self { - threads: threads.map(Thread::new).collect(), +impl Threads { + pub fn from_query(query: String) -> Self { + let mut res = Self { + threads: Vec::new(), i: 0, query, - } + }; + res.reload(); + res } pub fn reload(&mut self) { - if let Some(query) = &self.query { - self.threads = db::open(DatabaseMode::ReadOnly) - .unwrap() - .create_query(query) - .unwrap() - .search_threads() - .unwrap() - .map(Thread::new) - .collect(); - } + self.threads = db::open(DatabaseMode::ReadOnly) + .unwrap() + .create_query(&self.query) + .unwrap() + .search_threads() + .unwrap() + .map(Thread::new) + .collect(); } - pub fn init<W: Write>(&mut self, out: &mut W) { + pub fn init<W: Write>(&self, out: &mut W) { draw(&self, out); } @@ -80,6 +80,11 @@ impl<'d, 'q> Threads { Key::Char('i') => { self.threads[self.i].remove_tag("inbox"); } + Key::Char('s') => { + let sent = Threads::from_query(String::from("tag:sent")); + sent.init(out); + return Some(State::Threads(sent)); + } Key::Char('r') => self.reload(), _ => (), } |
