Skip to content

Commit

Permalink
enter and backspace handler added
Browse files Browse the repository at this point in the history
  • Loading branch information
Kacperacy committed Apr 30, 2024
1 parent f9635ed commit 407f395
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
8 changes: 7 additions & 1 deletion src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/tui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ impl<B: Backend> Tui<B> {
}

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

Expand Down

0 comments on commit 407f395

Please sign in to comment.