From cef095f1052f9a2b6dbf73569af3f35abbf72f2f Mon Sep 17 00:00:00 2001 From: Hunter Bown Date: Sun, 3 May 2026 13:50:36 -0500 Subject: [PATCH] fix(tui): disable bracketed paste + mouse capture in panic hook MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The panic hook only popped kitty keyboard flags, disabled raw mode, and left the alt-screen. Bracketed paste (`\e[?2004h`) and SGR mouse capture (`\e[?1006h`) stayed on, so any panic would leave the user's parent shell stuck wrapping pastes in `\e[200~…\e[201~` and printing `\e[<…M` mouse events. Mirror the clean-shutdown teardown so the shell is fully restored even when the TUI crashes. --- crates/tui/src/main.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/crates/tui/src/main.rs b/crates/tui/src/main.rs index 3a85dfbc..082a3b1c 100644 --- a/crates/tui/src/main.rs +++ b/crates/tui/src/main.rs @@ -543,9 +543,16 @@ async fn main() -> Result<()> { // Restore the terminal first so the panic message itself, plus the // user's shell after exit, are visible. Best-effort — we may not be // in raw / alt-screen mode if the panic happens pre-TUI. - use crossterm::event::PopKeyboardEnhancementFlags; + use crossterm::event::{ + DisableBracketedPaste, DisableMouseCapture, PopKeyboardEnhancementFlags, + }; use crossterm::terminal::{LeaveAlternateScreen, disable_raw_mode}; let _ = crossterm::execute!(std::io::stdout(), PopKeyboardEnhancementFlags); + // Best-effort: turn off bracketed paste + mouse capture so the user's + // parent shell doesn't get stuck wrapping pastes in `\e[200~…\e[201~` + // or printing `\e[<…M` on every click after a TUI panic. + let _ = crossterm::execute!(std::io::stdout(), DisableBracketedPaste); + let _ = crossterm::execute!(std::io::stdout(), DisableMouseCapture); let _ = disable_raw_mode(); let _ = crossterm::execute!(std::io::stdout(), LeaveAlternateScreen);