Flush terminal input after restoring modes

This commit is contained in:
Charlie Marsh
2026-07-05 21:18:45 -04:00
parent 7837f9e4e7
commit ed333328a1
2 changed files with 3 additions and 2 deletions
-1
View File
@@ -1826,7 +1826,6 @@ async fn run_ratatui_app(
reason = "TUI should no longer be displayed, so we can write to stderr."
)]
fn restore() {
tui::discard_terminal_input();
if let Err(err) = tui::restore_after_exit() {
eprintln!(
"failed to restore terminal. Run `reset` or restart your terminal to recover: {err}"
+3 -1
View File
@@ -347,13 +347,15 @@ pub(super) fn reapply_raw_mode_after_resume() -> Result<()> {
/// Restore the terminal after Codex is exiting.
///
/// Uses a stronger keyboard reset than [`restore`] so the parent shell recovers even if a
/// terminal missed the stack pop that normally pairs with [`set_modes`].
/// terminal missed the stack pop that normally pairs with [`set_modes`]. Queued input is flushed
/// only after restoration so late key repeats cannot escape to the parent shell.
pub fn restore_after_exit() -> Result<()> {
let mut first_error =
restore_common(RawModeRestore::Disable, KeyboardRestore::ResetAfterExit).err();
if let Err(err) = terminal_stderr::finish() {
first_error.get_or_insert(err);
}
flush_terminal_input_buffer();
match first_error {
Some(err) => Err(err),