fix(tui): prevent mouse garbling on exit, SIGTSTP suspend, and fragmented input#20704
Closed
agutmanstein-scale wants to merge 3 commits intoanomalyco:devfrom
Closed
fix(tui): prevent mouse garbling on exit, SIGTSTP suspend, and fragmented input#20704agutmanstein-scale wants to merge 3 commits intoanomalyco:devfrom
agutmanstein-scale wants to merge 3 commits intoanomalyco:devfrom
Conversation
…ragmented input Two bugs cause SGR mouse escape sequences to appear as garbled text: 1. **Post-exit garbling** (new fix): cleanupBeforeDestroy() calls setRawMode(false) before mouse tracking is disabled, creating a window where mouse events echo as raw bytes. Fixed by adding disableMouse() + stdin drain before setRawMode(false), matching the correct ordering already used in suspend(). 2. **In-session garbling** (ported from anomalyco#19520): StdinParser timeout fires mid-mouse-sequence during heavy event loop pressure, leaking individual bytes as KEY events. Fixed by patching three timeout paths with recovery flags and deferred processing. Also bumps DEFAULT_TIMEOUT_MS from 20 to 25ms for defense-in-depth. Patch targets @opentui/core@0.1.95 (current dev dependency). Upstream fix: anomalyco/opentui#905 Closes anomalyco#20458 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
When opencode receives SIGTSTP from an external source (code-server terminal management, job control, kill -TSTP), the process is suspended without terminal cleanup. Mouse tracking remains enabled, causing mouse events to echo as garbled escape sequences in the shell. Register SIGTSTP/SIGCONT handlers after renderer creation that call renderer.suspend()/resume() — the same cleanup the manual suspend keybind uses. The SIGTSTP handler removes itself before re-raising to allow default suspend behavior. Includes test-sigtstp-mouse.sh reproduction script. Upstream fix: anomalyco/opentui#907 Closes anomalyco#20506 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
When SIGCONT arrives without a prior SIGTSTP through our handler (e.g., code-server terminal refocus/reconnect), calling resume() adds a duplicate stdin listener — every keystroke is delivered twice, causing double character input like "ooppeennccooddee". Guard resume() with a suspendedBySigtstp flag so it only runs if our SIGTSTP handler actually called suspend(). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Contributor
|
This PR doesn't fully meet our contributing guidelines and PR template. What needs to be fixed:
Please edit this PR description to address the above within 2 hours, or it will be automatically closed. If you believe this was flagged incorrectly, please let a maintainer know. |
Contributor
|
This pull request has been automatically closed because it was not updated to meet our contributing guidelines within the 2-hour window. Feel free to open a new pull request that follows our guidelines. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issues
Closes #20458, closes #20506
Type of change
What does this PR do?
Combines three mouse/terminal garbling fixes into one PR:
1. Post-exit mouse garbling — patches
@opentui/core@0.1.95to calldisableMouse()beforesetRawMode(false)incleanupBeforeDestroy(), preventing mouse events from echoing as garbled text during renderer destruction. Also ports the StdinParser fragmentation fix (recovery flags for timeout paths that leaked mouse bytes as KEY events) and bumpsDEFAULT_TIMEOUT_MS20→25ms.2. SIGTSTP suspend garbling — registers SIGTSTP/SIGCONT handlers so external suspension (code-server terminal management, job control,
kill -TSTP) properly disables mouse tracking before the process suspends.3. SIGCONT double-input guard — gates
resume()on asuspendedBySigtstpflag so spurious SIGCONT signals (terminal refocus without prior SIGTSTP) don't add a duplicate stdin listener, which would cause every keystroke to appear twice.Upstream PRs
How did you verify your code works?
bun packages/opencode/test/cli/tui/test-stdin-parser.mjs— StdinParser fragmentation (9/9 pass)bun packages/opencode/test/cli/tui/test-destroy-mouse-cleanup.mjs— destroy ordering (5/5 pass)packages/opencode/test/cli/tui/test-sigtstp-mouse.sh— SIGTSTP reproduction scriptpackages/opencode/test/cli/tui/frag-pty.py— PTY wrapper for manual fragmentation testingChecklist
🤖 Generated with Claude Code