Skip to content

Commit

Permalink
Disable raw mode also on panic.
Browse files Browse the repository at this point in the history
  • Loading branch information
boxdot committed Jul 29, 2020
1 parent 6a39581 commit 51d4f0b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ thiserror = "1.0.20"
tokio = { version = "0.2.22", features = ["full"] }
base64 = "0.12.3"
itertools = "0.9.0"
scopeguard = "1.1.0"
9 changes: 6 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ async fn main() -> anyhow::Result<()> {
let mut app = App::try_new(args.verbose)?;

enable_raw_mode()?;
let _raw_mode_guard = scopeguard::guard((), |_| {
disable_raw_mode().unwrap();
});

let mut stdout = std::io::stdout();
execute!(stdout, EnterAlternateScreen, EnableMouseCapture)?;
Expand Down Expand Up @@ -90,13 +93,13 @@ async fn main() -> anyhow::Result<()> {
}
}

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

Ok(())
}

0 comments on commit 51d4f0b

Please sign in to comment.