diff --git a/Cargo.lock b/Cargo.lock index 004d49d..9eea78b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -269,6 +269,7 @@ dependencies = [ "crossterm", "dirs", "itertools", + "scopeguard", "serde", "serde_json", "structopt", diff --git a/Cargo.toml b/Cargo.toml index b715b62..ea2921f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/src/main.rs b/src/main.rs index aa38cd5..853d590 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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)?; @@ -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(()) }