From 76d6819994201a776c6be18193018a2eb0a42415 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Wed, 28 Apr 2021 22:47:15 +0200 Subject: only open db for as long as necessary --- src/state/mod.rs | 4 ++-- src/state/threads.rs | 29 ++++++++++++++++++++++++----- 2 files changed, 26 insertions(+), 7 deletions(-) (limited to 'src/state') 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>, +pub struct Threads { + pub threads: Vec, pub i: isize, } -impl<'d, 'q> Threads<'d, 'q> { +pub struct Thread { + subject: String, + authors: Vec, + 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(&mut self, out: &mut W) { draw(&self, out); } - pub fn tick(mut self, out: &mut W, key: Key) -> State<'d, 'q> { + pub fn tick(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(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(); } -- cgit v1.2.1