[PR #802] fix: disable mouse tracking before restoring cooked mode in finalizeDestroy #1575

Open
opened 2026-03-14 09:44:06 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/anomalyco/opentui/pull/802
Author: @adyavanapalli
Created: 3/11/2026
Status: 🔄 Open

Base: mainHead: fix/disable-mouse-before-cooked-mode


📝 Commits (1)

  • ecd5fe1 fix: disable mouse tracking before restoring cooked mode in finalizeDestroy

📊 Changes

1 file changed (+8 additions, -1 deletions)

View changed files

📝 packages/core/src/renderer.ts (+8 -1)

📄 Description

Summary

  • Fixes leaked SGR mouse escape sequences (e.g. 35;80;40M) appearing on the shell prompt after renderer destroy

Problem

When finalizeDestroy() tears down the renderer, it calls setRawMode(false) before mouse tracking has been disabled. In the window between restoring cooked mode and destroyRenderer() sending the mouse disable sequences, any mouse movement generates SGR escape events (\x1b[<35;80;40M) from the terminal. Since raw mode is off and the stdin listener has been removed, the terminal echoes these as visible garbage on the user's prompt.

This is easily reproduced in OpenCode: /exit while moving the mouse, and partial escape sequence bytes print after the shell prompt.

https://github.com/user-attachments/assets/8d481504-727e-4519-ad11-683f8f96c765

Fix

Call disableMouse() before setRawMode(false) in finalizeDestroy(), matching the ordering already used in suspend() (which does not have this bug).

The corrected sequence:

  1. disableMouse() — sends \x1b[?1000l, \x1b[?1002l, \x1b[?1006l while still in raw mode
  2. Remove stdin listener
  3. setRawMode(false) — restore cooked mode only after mouse tracking is off
  4. destroyRenderer() — clean up native resources

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/anomalyco/opentui/pull/802 **Author:** [@adyavanapalli](https://github.com/adyavanapalli) **Created:** 3/11/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/disable-mouse-before-cooked-mode` --- ### 📝 Commits (1) - [`ecd5fe1`](https://github.com/anomalyco/opentui/commit/ecd5fe1aa13cd8c53f5c0a85dc7ae33be4370253) fix: disable mouse tracking before restoring cooked mode in finalizeDestroy ### 📊 Changes **1 file changed** (+8 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `packages/core/src/renderer.ts` (+8 -1) </details> ### 📄 Description ## Summary - Fixes leaked SGR mouse escape sequences (e.g. `35;80;40M`) appearing on the shell prompt after renderer destroy ## Problem When `finalizeDestroy()` tears down the renderer, it calls `setRawMode(false)` before mouse tracking has been disabled. In the window between restoring cooked mode and `destroyRenderer()` sending the mouse disable sequences, any mouse movement generates SGR escape events (`\x1b[<35;80;40M`) from the terminal. Since raw mode is off and the stdin listener has been removed, the terminal echoes these as visible garbage on the user's prompt. This is easily reproduced in OpenCode: `/exit` while moving the mouse, and partial escape sequence bytes print after the shell prompt. https://github.com/user-attachments/assets/8d481504-727e-4519-ad11-683f8f96c765 ## Fix Call `disableMouse()` **before** `setRawMode(false)` in `finalizeDestroy()`, matching the ordering already used in `suspend()` (which does not have this bug). The corrected sequence: 1. `disableMouse()` — sends `\x1b[?1000l`, `\x1b[?1002l`, `\x1b[?1006l` while still in raw mode 2. Remove stdin listener 3. `setRawMode(false)` — restore cooked mode only after mouse tracking is off 4. `destroyRenderer()` — clean up native resources --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/opentui#1575
No description provided.