Skip to content

fix(tui): restore terminal modes on exit#20199

Closed
timrichardson wants to merge 1 commit intoanomalyco:devfrom
timrichardson:fix/tui-restore-terminal-modes-on-exit
Closed

fix(tui): restore terminal modes on exit#20199
timrichardson wants to merge 1 commit intoanomalyco:devfrom
timrichardson:fix/tui-restore-terminal-modes-on-exit

Conversation

@timrichardson
Copy link
Copy Markdown

@timrichardson timrichardson commented Mar 31, 2026

Issue for this PR

Closes #20207

Type of change

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

What does this PR do?

This fixes a TUI shutdown cleanup bug that can leave terminal mouse-reporting modes enabled after exit.

The change adds a shared terminal restore step that disables common mouse modes, disables bracketed paste, and restores cursor visibility. That restore step now runs around renderer teardown in both the normal exit path and the fatal-error exit path.

This matches the Linux issue in #20207 and is closely related to the Windows report in #11748. It also complements #18902, which resets leaked mouse tracking on startup after hard-kill scenarios.

How did you verify your code works?

  • cd packages/opencode && bun typecheck passes
  • verified locally against the reported symptom: stray mouse-report style codes appearing after TUI exit

Screenshots / recordings

Not a UI change.

Checklist

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

@github-actions
Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

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

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

Found a potentially related PR:

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

This is related because it addresses a similar issue with mouse tracking/SGR mouse mode being leaked in the terminal. While PR #18902 fixes the issue on startup (detecting and cleaning up leaked state), PR #20199 proactively prevents the leak by properly restoring terminal modes on exit. These are complementary approaches to the same problem.

@timrichardson timrichardson marked this pull request as ready for review March 31, 2026 07:06
@github-actions github-actions bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Mar 31, 2026
@github-actions
Copy link
Copy Markdown
Contributor

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

@timrichardson
Copy link
Copy Markdown
Author

this fix is not working reliably

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.

Linux/Ubuntu 25.10 VM: stray mouse escape sequences remain in terminal after exiting TUI

1 participant