Skip to content

fix(tui): reset leaked mouse tracking on startup#18902

Open
janah01 wants to merge 1 commit intoanomalyco:devfrom
janah01:fix/reset-mouse-tracking-on-startup
Open

fix(tui): reset leaked mouse tracking on startup#18902
janah01 wants to merge 1 commit intoanomalyco:devfrom
janah01:fix/reset-mouse-tracking-on-startup

Conversation

@janah01
Copy link
Copy Markdown

@janah01 janah01 commented Mar 24, 2026

Issue for this PR

Closes #18901

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

When the TUI is force-killed externally (taskkill /F on Windows, kill -9 on POSIX), for instance when installing OpenCode Desktop while OpenCode CLI is running, mouse tracking stays enabled in the terminal. The next opencode launch inherits this dirty state because the renderer starts from whatever baseline the terminal is already in.

This sends ?1000l ?1002l ?1003l ?1006l on startup to clear any leaked mouse modes before the renderer sets up its own. Disabling already-disabled modes is a safe no-op.

How did you verify your code works?

  • Launch on Windows Terminal, taskkill /F /PID, relaunch — terminal is clean
  • Normal exit (/exit) — no change in behavior
  • Ctrl+C exit — no change in behavior

Screenshots / recordings

N/A — not a UI change, terminal state fix.
Screenshot of the issue:
SCR-20260324-hxjd

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

When a previous process is killed externally (TerminateProcess on
Windows, SIGKILL on POSIX), mouse tracking can be left enabled in
the terminal. Send disable sequences before the renderer configures
its own mouse state to recover from a dirty baseline.
@github-actions github-actions bot added the needs:compliance This means the issue will auto-close after 2 hours. label Mar 24, 2026
@github-actions
Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

Based on my search results, I found two related PRs that address similar mouse tracking issues in the TUI:

  1. PR fix(tui): disable mouse tracking on exit to prevent terminal corruption #11019 - "fix(tui): disable mouse tracking on exit to prevent terminal corruption"

  2. PR fix: disable SGR mouse tracking on exit to prevent ASCII codes #6709 - "fix: disable SGR mouse tracking on exit to prevent ASCII codes"

The current PR (18902) is complementary to these - it handles the startup side of the problem (resetting leaked modes from force-killed processes), while the previous PRs addressed the exit side. These could potentially be part of the same comprehensive fix for terminal mouse tracking state management.

@github-actions github-actions bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Mar 24, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Windows] Hard-killed TUI leaves mouse reporting enabled; next launch does not reset terminal state

1 participant