From 0f097481b52aafb00b04f12c6fb3998b1e1db627 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Macio=C5=82ek?= Date: Fri, 10 May 2024 19:32:18 +0200 Subject: [PATCH] fps fix, cursor movement fix --- src/app.rs | 3 ++- src/main.rs | 8 +++++--- 2 files changed, 7 insertions(+), 4 deletions(-) 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(_, _) => {} }