aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/main.rs17
-rw-r--r--src/state/mod.rs4
-rw-r--r--src/state/threads.rs29
3 files changed, 34 insertions, 16 deletions
diff --git a/src/main.rs b/src/main.rs
index 7d29d72..49e76ac 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -16,18 +16,17 @@ fn main() {
// hide the cursor
let mut screen = termion::cursor::HideCursor::from(screen);
- // open database
- let db = notmuch::Database::open(&"/home/gustav/.mail", notmuch::DatabaseMode::ReadOnly).unwrap();
+ let mut threads = {
+ // open database
+ let db = notmuch::Database::open(&"/home/gustav/.mail", notmuch::DatabaseMode::ReadOnly).unwrap();
- // get threads
- let query = db.create_query("tag:inbox").unwrap();
- let threads = query.search_threads().unwrap().collect();
+ // get threads
+ let query = db.create_query("tag:inbox").unwrap();
+ let threads = query.search_threads().unwrap();
- // init initial state
- let mut threads = Threads {
- threads,
- i: 0,
+ Threads::new(threads)
};
+
threads.init(&mut screen);
let mut state = State::Threads(threads);
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();
}