From 407f3950b2acf997718d158aba05c4d278514cee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Macio=C5=82ek?= Date: Tue, 30 Apr 2024 21:53:02 +0200 Subject: [PATCH] enter and backspace handler added --- src/app.rs | 8 ++++++-- src/handler.rs | 8 +++++++- src/tui.rs | 2 ++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/app.rs b/src/app.rs index 356545e..0ed532f 100644 --- a/src/app.rs +++ b/src/app.rs @@ -28,7 +28,11 @@ impl App { self.running = false; } - pub fn append_str(&mut self, text: char) { - self.content.push(text) + pub fn append_char(&mut self, c: char) { + self.content.push(c); + } + + pub fn pop_char(&mut self) { + self.content.pop(); } } diff --git a/src/handler.rs b/src/handler.rs index 6396df5..43368e0 100644 --- a/src/handler.rs +++ b/src/handler.rs @@ -11,9 +11,15 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> { app.quit(); } } + KeyCode::Enter => { + app.append_char('\n'); + } + KeyCode::Backspace => { + app.pop_char(); + } _ => { if let KeyCode::Char(c) = key_event.code { - app.append_str(c) + app.append_char(c) } } } diff --git a/src/tui.rs b/src/tui.rs index 1c6df72..da69d06 100644 --- a/src/tui.rs +++ b/src/tui.rs @@ -35,7 +35,9 @@ impl Tui { } pub fn draw(&mut self, app: &mut App) -> AppResult<()> { + self.terminal.hide_cursor()?; self.terminal.draw(|frame| ui::render(app, frame))?; + self.terminal.show_cursor()?; Ok(()) }