diff options
Diffstat (limited to 'ticket/src/tui.rs')
-rw-r--r-- | ticket/src/tui.rs | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/ticket/src/tui.rs b/ticket/src/tui.rs index 9898e71..df62106 100644 --- a/ticket/src/tui.rs +++ b/ticket/src/tui.rs @@ -16,6 +16,7 @@ use configamajig::{ UserConfig, }; use crossterm::{ + cursor, event::{ self, DisableMouseCapture, @@ -34,6 +35,7 @@ use std::{ BufWriter, Write, }, + panic, sync::mpsc::{ self, Receiver, @@ -161,6 +163,32 @@ pub fn run() -> Result<()> { terminal.backend_mut().hide_cursor()?; terminal.clear()?; + // Setup panic handler so that screen gets reset properly + let old_hook = panic::take_hook(); + panic::set_hook(Box::new(move |panic_info| { + // Clean up terminal + queue!( + io::stdout().lock(), + LeaveAlternateScreen, + DisableMouseCapture, + cursor::Show + ) + .unwrap(); + disable_raw_mode().unwrap(); + // Load bearing println's without them the actual panic from the old hook + // Isn't flushed to the terminal + if let Some(location) = panic_info.location() { + println!( + "Panic occurred in file '{}' at line {}", + location.file(), + location.line() + ); + } else { + println!("Panic occurred but can't get location information..."); + } + old_hook(panic_info); + })); + // App let mut app = App { tabs: TabsState::new(vec!["Open", "Closed"]), |