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(()) }