mirror of
https://github.com/openai/codex.git
synced 2026-11-05 20:10:33 +00:00
Flush terminal input after restoring modes
This commit is contained in:
@@ -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}"
|
||||
|
||||
@@ -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),
|
||||
|
||||
Reference in New Issue
Block a user