fix(tui): patch mouse garbling on SIGTSTP suspend and exit + PTY reproducers#20587
fix(tui): patch mouse garbling on SIGTSTP suspend and exit + PTY reproducers#2058718vijayb 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>
- 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 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. |
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
|
The following comment was made by an LLM, it may be inaccurate: Related PRs Found: This PR (20587) is a consolidation/combination PR that references and builds upon two earlier PRs:
These are not duplicates but rather prerequisite PRs that are being combined and verified together in PR #20587. The current PR consolidates and adds test coverage for both fixes. |
|
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. |
Summary
Combines and verifies the three mouse garbling fixes:
@opentui/core@0.1.95: reordercleanupBeforeDestroy()to calldisableMouse()beforesetRawMode(false), preventing mouse events from garbling the shell on TUI exit. Also ports the StdinParser fragmentation fix.app.tsxso external suspension (code-server, job control) properly disables mouse tracking before the process suspends.Test scripts added
sigtstp-mouse-pty.py— PTY wrapper that auto-sends SIGTSTP after TUI startup and checks for?1003lin the output. Shows FAIL → PASS across the PR fix(tui): handle external SIGTSTP to prevent mouse garbling on suspend #20507 fix.post-exit-mouse-pty.py— PTY wrapper that snapshots the slave PTY ECHO state at the moment?1003larrives. Structural verification is covered bytest-destroy-mouse-cleanup.mjs(5/5 passing).Verification
🤖 Generated with Claude Code