From 101916910035531f99cb211c7319eafebb0cea4a Mon Sep 17 00:00:00 2001 From: objz Date: Sat, 25 Apr 2026 15:19:34 +0200 Subject: [PATCH] fix(tui): restore terminal on panic to prevent apparent freezes without a panic hook, any panic left the terminal in raw mode with the alternate screen active, making it look like the app froze. --- src/tui/mod.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/tui/mod.rs b/src/tui/mod.rs index f4a1e1c..d035851 100644 --- a/src/tui/mod.rs +++ b/src/tui/mod.rs @@ -12,6 +12,18 @@ pub mod widgets; pub type Tui = ratatui::DefaultTerminal; pub async fn show() -> color_eyre::Result<()> { + // restore the terminal before printing a panic. without this, a panic + // leaves raw mode + alternate screen active and looks like a freeze + let default_hook = std::panic::take_hook(); + std::panic::set_hook(Box::new(move |info| { + let _ = crossterm::execute!( + std::io::stdout(), + crossterm::event::PopKeyboardEnhancementFlags + ); + ratatui::restore(); + default_hook(info); + })); + let mut terminal = ratatui::init(); // opt into enhanced keyboard protocol to distinguish key press vs release