Skip to content

Commit

Permalink
fix(tui): quit a bit more gracefully
Browse files Browse the repository at this point in the history
when draw loop breaks it cleans up terminal
  • Loading branch information
EdJoPaTo committed Jan 13, 2021
1 parent 2bb2e42 commit 14ab1aa
Showing 1 changed file with 14 additions and 19 deletions.
33 changes: 14 additions & 19 deletions src/interactive/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,25 +89,12 @@ pub fn show(
terminal.draw(|f| ui::draw(f, &mut app).expect("failed to draw ui"))?;
match rx.recv()? {
Event::Key(event) => match event.code {
KeyCode::Char('q') => {
disable_raw_mode()?;
execute!(
terminal.backend_mut(),
LeaveAlternateScreen,
DisableMouseCapture
)?;
terminal.show_cursor()?;
break;
}
KeyCode::Char(c) => match c {
'q' => app.should_quit = true,
' ' => app.on_toggle(),
'h' => app.on_left(),
'j' => app.on_down()?,
'k' => app.on_up()?,
'l' => app.on_right(),
_ => {}
},
KeyCode::Char('q') => app.should_quit = true,
KeyCode::Char(' ') => app.on_toggle(),
KeyCode::Char('h') => app.on_left(),
KeyCode::Char('j') => app.on_down()?,
KeyCode::Char('k') => app.on_up()?,
KeyCode::Char('l') => app.on_right(),
KeyCode::Tab | KeyCode::BackTab => app.on_tab()?,
KeyCode::Enter => app.on_toggle(),
KeyCode::Left => app.on_left(),
Expand All @@ -127,5 +114,13 @@ pub fn show(
}
}

disable_raw_mode()?;
execute!(
terminal.backend_mut(),
LeaveAlternateScreen,
DisableMouseCapture
)?;
terminal.show_cursor()?;

Ok(())
}

0 comments on commit 14ab1aa

Please sign in to comment.