use std::io::{Write, stdin, stdout}; use termion::color; use termion::event::Key; use termion::input::TermRead; use termion::raw::IntoRawMode; use termion::screen::AlternateScreen; fn main() { let stdin = stdin(); let screen = AlternateScreen::from(stdout().into_raw_mode().unwrap()); // 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(); // get threads let query = db.create_query("tag:inbox").unwrap(); let threads = query.search_threads().unwrap(); let threads = threads .map(|t| format!("thread {:?}, {:?}", t.subject(), t.authors())) .collect(); let mut i: isize = 0; show_threads(&mut screen, &threads, i as usize); for c in stdin.keys() { match c.unwrap() { Key::Char('j') => i += 1, Key::Char('k') => i -= 1, Key::Char('q') => break, _ => () } i = i.rem_euclid(threads.len() as isize); show_threads(&mut screen, &threads, i as usize); } } fn show_threads(stdout: &mut W, threads: &Vec, highlight: usize) { write!(stdout, "{}", termion::clear::All).unwrap(); for (i, thread) in threads.iter().enumerate() { write!(stdout, "{}", termion::cursor::Goto(1, (i + 1) as u16)).unwrap(); let highlight = highlight == i; if highlight { write!(stdout, "{}", color::Fg(color::Red)).unwrap(); } write!(stdout, "{}", thread).unwrap(); if highlight { write!(stdout, "{}", color::Fg(color::Reset)).unwrap(); } } stdout.flush().unwrap(); }