Skip to content

fix(tui): reset terminal modes on shutdown - #32364

Closed
wgu9 wants to merge 2 commits into
anomalyco:devfrom
wgu9:wgu9/fix-tui-terminal-cleanup
Closed

wgu9 wants to merge 2 commits into
anomalyco:devfrom
wgu9:wgu9/fix-tui-terminal-cleanup

Conversation

@wgu9

@wgu9 wgu9 commented Jun 15, 2026

Copy link
Copy Markdown

Issue for this PR

Closes #20458

Related: #11748, #32336

Type of change

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

What does this PR do?

destroyRenderer() cleared the terminal title and then delegated to OpenTUI teardown. In some shutdown paths, terminal private modes can survive exit, especially mouse reporting and bracketed paste, leaving the user's shell in a broken state.

This PR centralizes the terminal reset contract in one TERMINAL_MODE_RESETS registry and writes the joined reset sequence before and after renderer.destroy(). The reset is idempotent and best-effort: a failed stdout write does not block renderer destruction.

The covered shutdown cases are:

  • normal renderer destruction
  • already-destroyed renderer cleanup
  • stdout write failure during cleanup
  • mouse tracking modes: basic, button-event, any-event, UTF-8, SGR, and URXVT
  • focus event reporting
  • bracketed paste
  • alternate screen
  • shared lifecycle consumers, since app.exit, scoped release, and SIGHUP already call destroyRenderer()

How did you verify your code works?

  • bun test test/util/renderer.test.ts
  • bun run typecheck from packages/tui
  • bunx oxlint packages/tui/src/util/renderer.ts packages/tui/test/util/renderer.test.ts
  • git diff --check

Screenshots / recordings

Not applicable. This is terminal teardown behavior covered by unit tests.

Checklist

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

@github-actions

Copy link
Copy Markdown
Contributor

Automated PR Cleanup

Thank you for contributing to opencode.

Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions.

This PR was closed because it matched the following cleanup criteria:

  • The PR was created more than 1 month ago
  • The PR had fewer than 2 positive reactions
  • Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR

PRs created within the last month are not affected by this cleanup.

If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate.

Thanks again for taking the time to contribute.

@XiongHaoTrigger

Copy link
Copy Markdown

Does PR need to receive a positive response in order to attract the attention of the maintainers?

@XiongHaoTrigger

Copy link
Copy Markdown

This issue still persists in version 1.18.14.

@wgu9

wgu9 commented Aug 9, 2026

Copy link
Copy Markdown
Author

@XiongHaoTrigger Thanks for confirming that this still happens on 1.18.14. The cleanup job used reactions as one of its criteria. This PR was closed because it was over a month old and had fewer than two positive reactions. The closure was automatic, not a sign that the bug was fixed.

I have rebased the branch onto the latest dev and checked the current OpenTUI 0.4.5 teardown path. Raw mode is still disabled before native renderer cleanup, so this OpenCode-side reset is still needed. The focused renderer tests pass, along with the packages/tui typecheck, oxlint, git diff --check, and the full pre-push typecheck.

Could a maintainer reopen this PR for review? The branch is current and ready.

@wgu9 wgu9 changed the title fix: reset terminal modes on tui shutdown fix(tui): reset terminal modes on shutdown Aug 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: mouse escape sequences garbled after TUI exit

2 participants