Skip to content

Reset TUI keyboard reporting on exit#19625

Merged
etraut-openai merged 2 commits intomainfrom
etraut/reset-keyboard-reporting-on-exit
Apr 28, 2026
Merged

Reset TUI keyboard reporting on exit#19625
etraut-openai merged 2 commits intomainfrom
etraut/reset-keyboard-reporting-on-exit

Conversation

@etraut-openai
Copy link
Copy Markdown
Collaborator

@etraut-openai etraut-openai commented Apr 26, 2026

Why

Codex enables enhanced keyboard reporting while the TUI owns the terminal. In iTerm2, exiting the TUI with Ctrl+C can intermittently leave the parent shell receiving raw CSI-u / modifyOtherKeys fragments instead of normal key input.

Final terminal cleanup should put the parent shell back into normal keyboard reporting even if the terminal misses the usual stack pop.

Fixes #19553.

What Changed

  • Move TUI keyboard enhancement setup and detection into tui/src/tui/keyboard_modes.rs.
  • Add an exit-only restore_after_exit() path that performs the normal keyboard enhancement pop plus unconditional keyboard enhancement and modifyOtherKeys resets.
  • Keep temporary restore paths, such as external-editor handoff, using the balanced stack pop behavior.

Confidence

Medium. This is a speculative fix: I was not able to reproduce the reported iTerm2 behavior manually, but the symptoms line up with terminal keyboard reporting state surviving Codex exit. The added reset sequences are scoped to final TUI shutdown and should be harmless when the terminal is already clean.

Copy link
Copy Markdown
Contributor

@fcoury-oai fcoury-oai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ran some sanity checks in iTerm2 on macOS:

  • Repeated Ctrl+C exits from the idle composer
  • Ctrl+C exit while Codex was active
  • External-program handoff and return
  • Ctrl+Z / fg suspend-resume before exiting
  • After each run, kept using the same shell session and verified normal typing, arrows, tab completion, and control keys still behaved normally

I am comfortable with approving this as a speculative fix.

@etraut-openai etraut-openai merged commit a61c785 into main Apr 28, 2026
25 checks passed
@etraut-openai etraut-openai deleted the etraut/reset-keyboard-reporting-on-exit branch April 28, 2026 15:51
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 28, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

iTerm2: Ctrl+C exit can intermittently leave terminal stuck in CSI-u mode and print 9;5:3u

2 participants