Skip to content

fix: restore enhanced keyboard modes on PTY teardown - #235

Merged
inureyes merged 2 commits into
mainfrom
fix/issue-234-keyboard-teardown
Jul 29, 2026
Merged

fix: restore enhanced keyboard modes on PTY teardown#235
inureyes merged 2 commits into
mainfrom
fix/issue-234-keyboard-teardown

Conversation

@inureyes

@inureyes inureyes commented Jul 29, 2026

Copy link
Copy Markdown
Member

Summary

Restore the local terminal's ordinary keyboard input mode after an interactive PTY session ends while a remote application has left enhanced keyboard reporting enabled.

What changed

  • Centralized bracketed-paste, keyboard, mouse, alternate-screen, and cursor teardown in one best-effort writer used by both TerminalStateGuard::Drop and force_terminal_cleanup().
  • Drain Kitty progressive-enhancement stacks and clear active flags before leaving the current screen, then repeat the reset on the main screen because the protocol maintains independent screen stacks.
  • Disable xterm modifyOtherKeys alongside the Kitty protocol reset.
  • Add exact-byte, idempotency, and writer-failure unit tests through the injectable writer.
  • Document a Ghostty plus Kitty/WezTerm manual validation procedure and the current outer-TUI state-preservation limitation.

Test plan

  • cargo test --lib pty::terminal::tests::
  • cargo test --test pty_integration_test
  • cargo fmt --all -- --check
  • cargo clippy --all-targets --all-features -- -D warnings
  • git diff --check
  • Repository pre-commit formatting and clippy hooks
  • Manual real-TTY verification in Ghostty and a second Kitty-keyboard-compatible terminal

Known limitation

Cleanup restores the ordinary shell baseline rather than an enhanced keyboard mode owned by an outer local TUI. Crossterm 0.29 exposes support detection but not the active flag value; adding a custom /dev/tty query would introduce blocking and input-reader races and is intentionally not part of this teardown fix. Exact state preservation is tracked in #236.

Closes #234

Reset leaked Kitty keyboard stacks and flags on both sides of alternate-screen teardown, and disable the xterm modifyOtherKeys fallback through one shared best-effort writer used by normal and forced cleanup.

Add exact-byte, idempotency, and failure-tolerance tests plus a documented real-terminal validation procedure and the outer-TUI preservation limitation.

Refs #234
@inureyes inureyes added type:bug Something isn't working priority:high High priority issue status:review Under review labels Jul 29, 2026
Describe the Kitty stack pop as a large bounded best-effort operation instead of implying an unbounded drain. Exact outer-TUI state preservation is tracked separately in #236.\n\nRefs #234
@inureyes inureyes added status:done Completed and removed status:review Under review labels Jul 29, 2026
@inureyes
inureyes merged commit 41642d9 into main Jul 29, 2026
3 checks passed
@inureyes
inureyes deleted the fix/issue-234-keyboard-teardown branch July 29, 2026 06:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

priority:high High priority issue status:done Completed type:bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: restore enhanced keyboard modes after PTY disconnect

1 participant