fix(tui): patch @opentui/core to prevent mouse garbling on exit and fragmented input#20462
Open
agutmanstein-scale wants to merge 1 commit intoanomalyco:devfrom
Open
fix(tui): patch @opentui/core to prevent mouse garbling on exit and fragmented input#20462agutmanstein-scale wants to merge 1 commit intoanomalyco:devfrom
agutmanstein-scale wants to merge 1 commit 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>
Contributor
|
The following comment was made by an LLM, it may be inaccurate: Related PR found:
This is not a duplicate but rather an evolution/enhancement of previous work. |
18vijayb
pushed a commit
to 18vijayb/opencode
that referenced
this pull request
Apr 2, 2026
- sigtstp-mouse-pty.py: wraps a command in a PTY, waits for mouse tracking to be enabled, sends SIGTSTP to the process group, then checks whether ?1003l was emitted before suspension. Demonstrates FAIL→PASS across PR anomalyco#20507. - post-exit-mouse-pty.py: wraps a command in a PTY and snapshots the slave PTY's ECHO flag at the moment ?1003l arrives at the master. Structural verification for PR anomalyco#20462 ordering is covered by test-destroy-mouse-cleanup.mjs. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.
Issue for this PR
Closes #20458
Type of change
What does this PR do?
Patches
@opentui/core@0.1.95to fix two separate bugs that cause SGR mouse escape sequences to appear as garbled text in the terminal:1. Post-exit mouse garbling (new fix)
When the renderer is destroyed,
cleanupBeforeDestroy()callsstdin.setRawMode(false)(re-enabling terminal ECHO) before mouse tracking is disabled. Any mouse events arriving during this window get echoed as raw escape sequence bytes like35;89;19M35;84;20M35....The correct ordering already exists in
suspend(). This patch applies the same pattern tocleanupBeforeDestroy():disableMouse()— mouse off while raw mode is still on (no ECHO)setRawMode(false)— raw mode off lastUpstream fix: anomalyco/opentui#905
2. In-session mouse garbling (ported from #19520)
When SGR mouse escape sequences arrive fragmented across multiple stdin chunks (due to event loop pressure from LLM streaming + TUI rendering), the StdinParser's timeout fires mid-sequence and leaks individual bytes as KEY events. Three timeout paths are patched:
esc_recoverytimeout: changed toemitOpaqueResponse+ recovery flagcsitimeout: added recovery flag for subsequent<routingesc_less_mousetimeout: changed to deferred wait instead of flushAlso bumps
DEFAULT_TIMEOUT_MSfrom 20 to 25ms for defense-in-depth.How did you verify your code works?
bun packages/opencode/test/cli/tui/test-stdin-parser.mjs— StdinParser fragmentation tests (9/9 pass)bun packages/opencode/test/cli/tui/test-destroy-mouse-cleanup.mjs— structural tests verifying correct ordering in the patched code (5/5 pass)packages/opencode/test/cli/tui/frag-pty.py— PTY wrapper for manual end-to-end testingChecklist
🤖 Generated with Claude Code