diff --git a/src/ui/mail_tab.rs b/src/ui/mail_tab.rs index 4bf6687..437622d 100644 --- a/src/ui/mail_tab.rs +++ b/src/ui/mail_tab.rs @@ -43,6 +43,34 @@ fn humanize_timestamp(date: DateTime) -> String { } impl MailTabState { + pub fn move_down(&mut self) { + if self.message_uids.is_empty() { + return; + } + let len = self.message_uids.len(); + if let Some(selected) = self.message_list.selected() { + if selected + 1 < len { + self.message_list.select(Some(selected + 1)); + } + } else { + self.message_list.select(Some(0)); + } + } + + pub fn move_up(&mut self) { + if self.message_uids.is_empty() { + return; + } + let len = self.message_uids.len(); + if let Some(selected) = self.message_list.selected() { + if selected >= 1 { + self.message_list.select(Some(selected - 1)); + } + } else { + self.message_list.select(Some(len - 1)); + } + } + pub fn render(&mut self, f: &mut FrameType, area: Rect) { let chunks = Layout::default() .direction(Direction::Horizontal) diff --git a/src/ui/mod.rs b/src/ui/mod.rs index dd0e779..5690c17 100644 --- a/src/ui/mod.rs +++ b/src/ui/mod.rs @@ -77,6 +77,8 @@ pub async fn run_ui( if let Event::Key(KeyEvent { code, .. }) = event { match code { KeyCode::Char('q') => break, + KeyCode::Char('j') => mail_tab.move_down(), + KeyCode::Char('k') => mail_tab.move_up(), _ => {} } }