Skip to content

Commit

Permalink
Merge pull request #65 from drdo/defer-terminal-restore
Browse files Browse the repository at this point in the history
Use defer! rather than panic hooks for terminal restoration
  • Loading branch information
drdo authored Aug 13, 2024
2 parents d34af98 + af7c35a commit 660c761
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
#![feature(panic_update_hook)]

use std::{
fs,
io::stderr,
panic,
sync::{
atomic::{AtomicBool, Ordering},
mpsc::{self, RecvTimeoutError},
Expand Down Expand Up @@ -126,15 +123,13 @@ fn main() -> anyhow::Result<()> {

// UI
stderr().execute(EnterAlternateScreen)?;
panic::update_hook(|prev, info| {
defer! {
stderr().execute(LeaveAlternateScreen).unwrap();
prev(info);
});
}
enable_raw_mode()?;
panic::update_hook(|prev, info| {
defer! {
disable_raw_mode().unwrap();
prev(info);
});
}
let mut terminal = Terminal::new(CrosstermBackend::new(stderr()))?;
terminal.clear()?;

Expand Down Expand Up @@ -209,9 +204,6 @@ fn main() -> anyhow::Result<()> {
}
}

disable_raw_mode()?;
stderr().execute(LeaveAlternateScreen)?;

for line in output_paths {
println!("{}", escape_for_exclude(line.as_str()));
}
Expand Down

0 comments on commit 660c761

Please sign in to comment.