diff options
| author | Gustav Sörnäs <gustav@sornas.net> | 2021-04-28 23:24:15 +0200 |
|---|---|---|
| committer | Gustav Sörnäs <gustav@sornas.net> | 2021-04-28 23:24:15 +0200 |
| commit | 47878c556e190e16f67d1c593f378b1e9422611d (patch) | |
| tree | 93edc814ac0c2aa7568d290e4791df580ad72e4f /src | |
| parent | 49ee6470ad8f748f85bf1c9ad4364d47f8b2252b (diff) | |
| download | mail-47878c556e190e16f67d1c593f378b1e9422611d.tar.gz | |
isize -> usize
Diffstat (limited to 'src')
| -rw-r--r-- | src/state/threads.rs | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/src/state/threads.rs b/src/state/threads.rs index 9d81e09..78dc795 100644 --- a/src/state/threads.rs +++ b/src/state/threads.rs @@ -7,7 +7,7 @@ use termion::{color, event::Key}; pub struct Threads { threads: Vec<Thread>, - i: isize, + i: usize, query: Option<String>, } @@ -61,9 +61,6 @@ impl<'d, 'q> Threads { .unwrap() .map(Thread::new) .collect(); - if self.i >= self.threads.len() as isize { - self.i = self.threads.len() as isize - 1; - } } } @@ -74,15 +71,22 @@ impl<'d, 'q> Threads { 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, + Key::Char('k') => self.i = + if self.i == 0 { + self.threads.len() + } else { + self.i - 1 + }, Key::Char('i') => { - self.threads[self.i as usize].remove_tag("inbox"); + self.threads[self.i].remove_tag("inbox"); } Key::Char('r') => self.reload(), _ => (), } - self.i = self.i.rem_euclid(self.threads.len() as isize); - draw(&self, out); + if !self.threads.is_empty() { + self.i = self.i.rem_euclid(self.threads.len()); + draw(&self, out); + } State::Threads(self) } } @@ -92,7 +96,7 @@ fn draw<W: Write>(state: &Threads, out: &mut W) { 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; + let highlight = i == state.i; if highlight { write!(out, "{}", color::Fg(color::Red)).unwrap(); } |
