fix(tui): restore raw mode conditionally

This commit is contained in:
Paulo Aboim Pinto
2026-05-27 17:11:12 +02:00
committed by Hunter Bown
parent ab95512c8f
commit f1afcf316f
+14 -5
View File
@@ -239,15 +239,24 @@ impl ShellDispatcher {
}
}
// Disable raw mode; guard restores it even on `?` early return.
let _ = crossterm::terminal::disable_raw_mode();
struct FgRawModeGuard;
// Disable raw mode; guard restores it only if it was already enabled.
let raw_mode_was_enabled = crossterm::terminal::is_raw_mode_enabled().unwrap_or(false);
if raw_mode_was_enabled {
let _ = crossterm::terminal::disable_raw_mode();
}
struct FgRawModeGuard {
restore: bool,
}
impl Drop for FgRawModeGuard {
fn drop(&mut self) {
let _ = crossterm::terminal::enable_raw_mode();
if self.restore {
let _ = crossterm::terminal::enable_raw_mode();
}
}
}
let _guard = FgRawModeGuard;
let _guard = FgRawModeGuard {
restore: raw_mode_was_enabled,
};
let mut cmd = self.build_command(shell_command);
cmd.current_dir(cwd);