diff --git a/src/app.rs b/src/app.rs index b78cdee..76e0354 100644 --- a/src/app.rs +++ b/src/app.rs @@ -75,12 +75,13 @@ impl App { } } } + if direction.y > 0 && self.cursor_position.y > 0 { self.cursor_position.y -= 1; if self.cursor_position.x > self.content[self.cursor_position.y].len() { self.cursor_position.x = self.content[self.cursor_position.y].len(); } - } else if direction.y < 0 && self.cursor_position.y < self.content.len() - 1 { + } else if direction.y < 0 && self.cursor_position.y < self.content.len().saturating_sub(1) { self.cursor_position.y += 1; if self.cursor_position.x > self.content[self.cursor_position.y].len() { self.cursor_position.x = self.content[self.cursor_position.y].len(); diff --git a/src/main.rs b/src/main.rs index b2a01aa..f545c71 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,13 +14,15 @@ async fn main() -> AppResult<()> { let events = EventHandler::new(250); let mut tui = Tui::new(terminal, events); tui.init()?; + tui.draw(&mut app)?; while app.running { - tui.draw(&mut app)?; - match tui.events.next().await? { Event::Tick => app.tick(), - Event::Key(key_event) => handle_key_events(key_event, &mut app)?, + Event::Key(key_event) => { + handle_key_events(key_event, &mut app)?; + tui.draw(&mut app)?; + } Event::Mouse(_) => {} Event::Resize(_, _) => {} }