diff options
-rw-r--r-- | .dev-suite/ticket/closed/create-a-panic-handler-for-ticket-tui.toml (renamed from .dev-suite/ticket/open/create-a-panic-handler-for-ticket-tui.toml) | 2 | ||||
-rw-r--r-- | ticket/src/tui.rs | 28 |
2 files changed, 29 insertions, 1 deletions
diff --git a/.dev-suite/ticket/open/create-a-panic-handler-for-ticket-tui.toml b/.dev-suite/ticket/closed/create-a-panic-handler-for-ticket-tui.toml index 7b61c45..9847148 100644 --- a/.dev-suite/ticket/open/create-a-panic-handler-for-ticket-tui.toml +++ b/.dev-suite/ticket/closed/create-a-panic-handler-for-ticket-tui.toml @@ -1,5 +1,5 @@ title = 'Create a panic handler for ticket tui' -status = 'Open' +status = 'Closed' id = '9b344c00-2e3d-11ea-bc2d-b4e1317c6ecc' assignees = [[ '64c00ccc-761e-4484-86ac-904e461bb300', 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"]), |