fix: fix cleanup mouse events

This commit is contained in:
Catriel Müller
2026-05-22 08:59:50 -03:00
parent 656572c2cf
commit 3e8f6d7bc7
3 changed files with 14 additions and 2 deletions
@@ -1,3 +1,5 @@
import fs from "node:fs"
/**
* Write escape sequences to disable terminal input modes and reset terminal state.
* This is a safety net to ensure the terminal is clean after exit, even if the renderer's
@@ -23,11 +25,16 @@ export function kitty() {
export function sequences() {
return [
"\x1b[?9l", // disable X10 mouse tracking
"\x1b[?1000l", // disable normal mouse tracking
"\x1b[?1001l", // disable highlight mouse tracking
"\x1b[?1002l", // disable button-event mouse tracking
"\x1b[?1003l", // disable any-event mouse tracking (all movement)
"\x1b[?1005l", // disable UTF-8 extended mouse mode
"\x1b[?1006l", // disable SGR extended mouse mode
"\x1b[?1007l", // disable alternate scroll mode
"\x1b[?1015l", // disable RXVT mouse mode
"\x1b[?1016l", // disable SGR pixel mouse mode
"\x1b[?2004l", // disable bracketed paste
"\x1b[?1004l", // disable focus tracking
"\x1b[?1l", // disable application cursor keys
@@ -42,7 +49,7 @@ export function sequences() {
export function resetTerminalState() {
try {
process.stdout.write(sequences().join(""))
fs.writeSync(process.stdout.fd, sequences().join(""))
} catch (err) {
console.error("resetTerminalState failed", err)
}
@@ -71,11 +71,16 @@ test("resets common terminal input modes", () => {
expect(sequences()).toEqual(
expect.arrayContaining([
"\x1b[?9l",
"\x1b[?1000l",
"\x1b[?1001l",
"\x1b[?1002l",
"\x1b[?1003l",
"\x1b[?1005l",
"\x1b[?1006l",
"\x1b[?1007l",
"\x1b[?1015l",
"\x1b[?1016l",
"\x1b[?2004l",
"\x1b[?1004l",
"\x1b[?1l",