Uh oh!
There was an error while loading. Please reload this page.
fix(tui): disable mouse tracking on exit to prevent terminal corruption - #11019
fix(tui): disable mouse tracking on exit to prevent terminal corruption#11019d-init-d wants to merge 1 commit into
Conversation
Fixesanomalyco#6912 When pressing Ctrl+C to exit OpenCode on Windows, the terminal was left in mouse tracking mode, causing raw SGR escape sequences to flood the terminal on mouse movement. Changes: - Add cleanupTerminal() that synchronously writes ANSI disable sequences using fs.writeSync to ensure immediate execution before process exit - Add destroyRenderer() export for SIGINT handler to properly cleanup - Register SIGINT handler in tui() to catch Ctrl+C and cleanup properly - Update ErrorComponent to use destroyRenderer() for consistent cleanup The fix covers all mouse tracking modes: - X11 mouse tracking (1000) - Button-event tracking (1002) - Any-event tracking (1003) - SGR extended mode (1006) - URXVT extended mode (1015) Tested on Windows Terminal with PowerShell.
The following comment was made by an LLM, it may be inaccurate: Potential Duplicate/Related PRs Found:
Both PRs are tackling the same underlying issue with terminal state cleanup on exit, particularly on Windows. The current PR (#11019) appears to be a more comprehensive solution compared to PR #8355 with better ANSI sequence coverage and improved code organization. |
f1ae801 to
08fa7f7CompareClosing this pull request because it has had no updates for more than 60 days. If you plan to continue working on it, feel free to reopen or open a new PR. |
Fixes#6912
Problem
When pressing Ctrl+C to exit OpenCode on Windows, the terminal is left in mouse tracking mode. This causes raw SGR mouse tracking escape sequences to flood the terminal on every mouse movement, rendering the terminal unusable:
The issue occurs because:
process.exit(0)was called before cleanup sequences could be flushedrenderer.destroy()meant sequences might not reach the terminalSolution
Added synchronous terminal cleanup using
fs.writeSync()to ensure ANSI disable sequences are written immediately before process exit:cleanupTerminal()- Synchronously writes disable sequences directly to stdout (fd 1)destroyRenderer()- Exported function for SIGINT handler to properly cleanuptui()to catch Ctrl+C and call cleanupANSI Sequences Covered
The fix disables all common mouse tracking modes:
\x1b[?1000l\x1b[?1002l\x1b[?1003l\x1b[?1006l\x1b[?1015l\x1b[?25hChanges
packages/opencode/src/cli/cmd/tui/context/exit.tsx:cleanupTerminal()for synchronous cleanupdestroyRenderer()export for external userenderer.destroy()packages/opencode/src/cli/cmd/tui/app.tsx:destroyRendererfrom exit contexttui()functionErrorComponentto usedestroyRenderer()Testing
bun devoropencodeCtrl+Cto exitRelated Issues
Note
This PR provides a similar fix to #8355 but with improvements: