diff options
| author | Gustav Sörnäs <gustav@sornas.net> | 2021-04-26 22:54:32 +0200 |
|---|---|---|
| committer | Gustav Sörnäs <gustav@sornas.net> | 2021-04-26 22:54:32 +0200 |
| commit | abecc3b586a1d955fb0b1fe8c03132f755c559c3 (patch) | |
| tree | 8dff1add8a035707e3803105c4c83feb03202dbe /src/state | |
| parent | 388f0bb7d8877d16261d8e1fe2613a5c92ea6d37 (diff) | |
| download | mail-abecc3b586a1d955fb0b1fe8c03132f755c559c3.tar.gz | |
move out thread state
Diffstat (limited to 'src/state')
| -rw-r--r-- | src/state/mod.rs | 7 | ||||
| -rw-r--r-- | src/state/threads.rs | 43 |
2 files changed, 50 insertions, 0 deletions
diff --git a/src/state/mod.rs b/src/state/mod.rs new file mode 100644 index 0000000..fc563e7 --- /dev/null +++ b/src/state/mod.rs @@ -0,0 +1,7 @@ +mod threads; + +pub use threads::Threads; + +pub enum State<'d, 'q> { + Threads(Threads<'d, 'q>), +} diff --git a/src/state/threads.rs b/src/state/threads.rs new file mode 100644 index 0000000..20b365e --- /dev/null +++ b/src/state/threads.rs @@ -0,0 +1,43 @@ +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 i: isize, +} + +impl<'d, 'q> Threads<'d, 'q> { + 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> { + match key { + Key::Char('j') => self.i += 1, + Key::Char('k') => self.i -= 1, + _ => (), + } + self.i = self.i.rem_euclid(self.threads.len() as isize); + draw(&self, out); + State::Threads(self) + } +} + +fn draw<W: Write>(state: &Threads, out: &mut W) { + write!(out, "{}", termion::clear::All).unwrap(); + + for (i, thread) in state.threads.iter().enumerate() { + write!(out, "{}", termion::cursor::Goto(1, (i + 1) as u16)).unwrap(); + let highlight = i == state.i as usize; + 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(); +} |
