From 37f3bd2a78d6bd340fbe6b013b4b4a58a2ed260f Mon Sep 17 00:00:00 2001 From: suri-codes Date: Tue, 7 Apr 2026 10:02:36 -0700 Subject: [PATCH] feat: panic hook now exits tui --- src/errors.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/errors.rs b/src/errors.rs index d8160f8..e8bd80c 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -1,3 +1,11 @@ +use std::io::stdout; + +use crossterm::{ + cursor, + event::{DisableBracketedPaste, DisableMouseCapture}, + terminal::LeaveAlternateScreen, +}; + /// Sets the panic-hook to be customized color-eyre `panic_hook`. /// /// Additionally the panic handler prints different information @@ -15,7 +23,13 @@ pub fn init() -> color_eyre::Result<()> { eyre_hook.install()?; std::panic::set_hook(Box::new(move |panic_info| { - //TODO: exit from terminal if the app is in a terminal + // exit from terminal if the app is in a terminal + if crossterm::terminal::is_raw_mode_enabled().unwrap() { + let _ = crossterm::execute!(stdout(), DisableBracketedPaste); + let _ = crossterm::execute!(stdout(), DisableMouseCapture); + let _ = crossterm::execute!(stdout(), LeaveAlternateScreen, cursor::Show); + let _ = crossterm::terminal::disable_raw_mode(); + } // in release mode, do human_panic printing #[cfg(not(debug_assertions))] -- 2.51.2