Skip to content

fix: disable mouse tracking on terminal exit (#838)#841

Open
MrRealORG wants to merge 1 commit into
XiaomiMiMo:mainfrom
MrRealORG:fix/auto-0616-mouse-cleanup-on-exit
Open

fix: disable mouse tracking on terminal exit (#838)#841
MrRealORG wants to merge 1 commit into
XiaomiMiMo:mainfrom
MrRealORG:fix/auto-0616-mouse-cleanup-on-exit

Conversation

@MrRealORG

Copy link
Copy Markdown

Summary

Fixes #838: terminal mouse tracking not cleaned up on abnormal exit.

Problem

When MiMo Code is killed by an external process (e.g. another TUI tool), the terminal mouse event tracking escape sequences are not disabled. This leaves the terminal in mouse-tracking mode, causing garbage output like [555;row;colM on every mouse movement.

Root Cause

The exit handler in exit.tsx writes SGR reset + cursor show + OSC color resets, but does not send mouse tracking disable sequences. The renderer.destroy() should handle this during normal exit, but on abnormal exit (SIGTERM from external process), the renderer teardown may not complete.

Fix

Two-layer defense:

  1. Async exit handler: Added mouse tracking disable sequences (modes 1000, 1002, 1003, 1005, 1006, 1015) to the ANSI cleanup string that runs during the normal exit flow.

  2. Synchronous process.on("exit") hook: A safety net that runs even when the async exit handler cannot complete (e.g. SIGTERM from an external process). Node.js guarantees process.on("exit") callbacks run synchronously before the process exits, regardless of how the process was signaled.

Mouse modes disabled

Mode Description
?1000 Basic tracking (X10 mouse)
?1002 Button-event tracking
?1003 Any-event tracking
?1005 UTF-8 extended coordinates
?1006 SGR extended coordinates
?1015 URXVT extended coordinates

Test Plan

  • Launch MiMo Code, then kill -TERM <pid> from another terminal → verify no garbage on mouse move
  • Normal exit (ESC ESC /quit) → verify terminal works normally
  • Verify mouse still works during normal MiMo Code usage

Closes #838

When MiMo Code is killed by an external process (SIGTERM, another TUI
tool, etc.), the renderer may not complete its teardown, leaving the
terminal in mouse-tracking mode. This causes garbage escape sequences
like [555;row;colM on every mouse movement.

Fix:
- Add mouse tracking disable sequences to the async exit handler's
  ANSI cleanup string (modes 1000, 1002, 1003, 1005, 1006, 1015)
- Register a synchronous process.on('exit') hook as a safety net —
  this runs even when the async exit cannot complete (e.g. SIGTERM
  from an external process), ensuring cleanup always happens
@Ivaloz

Ivaloz commented Jun 16, 2026

Copy link
Copy Markdown

Summary

  • Add mouse event tracking disable sequences (\e[?1000l, \e[?1002l, \e[?1003l, \e[?1006l) to the TUI exit handler's ANSI cleanup string
  • Fixes terminal garbage output ([row;colM sequences) when MiMo Code is killed by an external process

Problem

When MiMo Code is killed by signal (e.g. another TUI tool like Qoder terminates it), the terminal's mouse event tracking is not properly disabled. This leaves the terminal in mouse-tracking mode, producing garbage escape sequences on every mouse move.

Root Cause

packages/opencode/src/cli/cmd/tui/context/exit.tsx wrote SGR reset + cursor show + OSC color resets on exit, but did not send mouse tracking disable sequences. On abnormal exit, renderer.destroy() may not complete its teardown.

Fix

Prepend \x1b[?1000l\x1b[?1002l\x1b[?1003l\x1b[?1006l to the exit ANSI sequence, covering all mouse event modes (X10/buttons/all-motion/SGR). Works in conjunction with existing SIGINT/SIGTERM/SIGHUP/beforeExit signal handlers from #252.

TEST

Closes #838

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.

fix: terminal mouse tracking not cleaned up on abnormal exit

2 participants