Skip to content

bug: mouse escape sequences garbled after TUI exit #20458

Description

@agutmanstein-scale

Description

After exiting the opencode TUI (via quit, Ctrl+C, or process stop), mouse escape sequences appear as garbled text in the terminal:

35;89;19M35;84;20M35;76;22M35;71;23M35;67;23M35;67;24M35;67;25M35...

This is a separate issue from in-session mouse garbling (#3199 / PR #19520). The in-session bug is about fragmented SGR sequences leaking through StdinParser timeouts during active use. This bug occurs after the TUI has exited.

Root Cause

This is an upstream bug in @opentui/core's cleanupBeforeDestroy() method. During renderer destruction, stdin.setRawMode(false) is called (re-enabling terminal ECHO) before mouse tracking is disabled. Any mouse events arriving during this window get echoed as raw escape sequence bytes.

The correct ordering already exists in @opentui/core's suspend() method, which calls disableMouse() before setRawMode(false).

Upstream issue: anomalyco/opentui#904
Upstream fix PR: anomalyco/opentui#905

Reproduction

  1. Run opencode
  2. Move the mouse while the TUI is active
  3. Exit the TUI (quit or Ctrl+C)
  4. Move the mouse in the shell immediately after exit
  5. Garbled escape sequences appear

Workaround

A patchedDependencies patch for @opentui/core can fix this by adding disableMouse() + stdin drain before setRawMode(false) in cleanupBeforeDestroy(). A PR with this patch is forthcoming.

Environment

  • macOS / Linux
  • Affects @opentui/core@0.1.90 and @opentui/core@0.1.95

Activity

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions