opencode icon indicating copy to clipboard operation
opencode copied to clipboard

fix: reset terminal modes on tui shutdown

Open wgu9 opened this issue 5 months ago • 0 comments

Issue for this PR

Closes #20458

Related: #11748, #32336

Type of change

  • [x] 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

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

wgu9 avatar Jun 15 '26 02:06 wgu9