Skip to content

feat: preserve outer TUI keyboard state - #237

Merged
inureyes merged 6 commits into
mainfrom
feature/issue-236-preserve-keyboard-state
Jul 29, 2026
Merged

feat: preserve outer TUI keyboard state#237
inureyes merged 6 commits into
mainfrom
feature/issue-236-preserve-keyboard-state

Conversation

@inureyes

@inureyes inureyes commented Jul 29, 2026

Copy link
Copy Markdown
Member

Summary

  • Capture raw Kitty enhancement flags independently for the main and alternate screens, together with xterm modifyOtherKeys and DEC private mode 1049, in DA-delimited transactions bounded to 100 ms per screen before the PTY input reader starts.
  • Preserve every post-DA, unrelated, malformed, partial, or concurrently typed byte in order and forward it through the existing local escape detector and PTY input path.
  • Normalize both screens to a legacy keyboard baseline for the remote session without popping the outer application's Kitty stacks, then reset remote leaks and restore both captured screen states on normal, forced, and repeated cleanup paths.
  • Track only successfully delivered, filtered 7-bit DEC 1049 transitions with an OSC/DCS/APC/PM/SOS-aware streaming parser. Cleanup safely leaves a remote-owned 1049 screen when bssh began on main, while avoiding destructive 1049h when bssh began inside an outer alternate-screen TUI.
  • Reject concurrent raw and deferred-raw terminal guards with an atomic RAII owner so process-global cleanup snapshots cannot overwrite each other, while retaining the fix: restore enhanced keyboard modes after PTY disconnect #234 ordinary-shell fallback when state capture is unsupported or incomplete.

Test plan

  • cargo test --lib (1,280 passed, 9 ignored)
  • cargo test --test pty_integration_test (18 passed)
  • cargo clippy --all-targets --all-features -- -D warnings
  • cargo fmt --all -- --check
  • git diff --check
  • Manual outer-TUI verification in Ghostty and Kitty or WezTerm (procedure documented; unavailable in the automated execution environment)

Closes #236

inureyes added 2 commits July 29, 2026 16:21
Capture Kitty keyboard flags, xterm modifyOtherKeys, and alternate-screen ownership before starting the PTY input task. Preserve unrelated input bytes and restore the captured state across normal and forced cleanup while retaining the legacy baseline fallback.

Track remote screen transitions so an unchanged outer alternate buffer is not cleared during teardown.

Refs #236
Publish the captured terminal protocol state before bracketed-paste setup can fail, allowing outer forced cleanup to restore it even when guard construction returns an error.

Keep the private protocol snapshot on TerminalStateGuard so the public TerminalState struct remains source-compatible.

Refs #236
@inureyes inureyes added status:review Under review type:enhancement New feature or request priority:medium Medium priority issue labels Jul 29, 2026
inureyes added 4 commits July 29, 2026 16:39
Trust terminal query replies only before each transaction's first primary DA sentinel, preserve all untrusted bytes, and discard incomplete snapshots.

Capture Kitty flags independently on both screen buffers with non-clearing DEC mode 47 transitions, normalize remote input without popping outer stacks, and restore both screens during teardown. Enforce single raw-terminal ownership so concurrent guards cannot race the global snapshot.

Refs #236
@inureyes inureyes added status:done Completed and removed status:review Under review labels Jul 29, 2026
@inureyes
inureyes merged commit 63d2b31 into main Jul 29, 2026
3 checks passed
@inureyes
inureyes deleted the feature/issue-236-preserve-keyboard-state branch July 29, 2026 08:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

priority:medium Medium priority issue status:done Completed type:enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: preserve outer TUI enhanced keyboard state across PTY sessions

1 participant