Skip to content

Serialize the SGR mouse encoding (add IModes.mouseEncoding) - #6174

Open
nedtwigg wants to merge 1 commit into
xtermjs:masterfrom
diffplug:mouse-encoding-serialize
Open

nedtwigg wants to merge 1 commit into
xtermjs:masterfrom
diffplug:mouse-encoding-serialize

Conversation

@nedtwigg

@nedtwigg nedtwigg commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

SerializeAddon restores the mouse tracking mode (?9 / ?1000 / ?1002 / ?1003) but not the mouse encoding. If a terminal is serialized while an app has SGR (CSI ? 1006 h) or SGR-pixels (CSI ? 1016 h) reporting on, it comes back with the default encoding. The app then gets X10-style reports it isn't expecting, and clicks past column 223 aren't reported at all.

The addon builds its mode preamble from terminal.modes, which has no encoding member, so this PR adds one:

  • IModes.mouseEncoding: 'default' | 'sgr' | 'sgr-pixels' in xterm.d.ts and xterm-headless.d.ts. It's read from mouseStateService.activeEncoding, next to where mouseTrackingMode reads activeProtocol, and the values follow mouseTrackingMode's lowercase style.
  • SerializeAddon emits CSI ? 1006 h or CSI ? 1016 h for a non-default encoding. It's emitted separately from the tracking mode, because xterm.js tracks the two separately and an app may set the encoding before it turns tracking on.

Motivation

Dormouse moves live terminals between windows by serializing each one and replaying it into a new Terminal. Right now we work around this bug by reading terminal._core.mouseStateService.activeEncoding and appending the DECSET ourselves. With this PR we can delete that.

The same gap affects VS Code: on reconnect, triggerReplay() in src/vs/platform/terminal/node/ptyService.ts replays serialize() from its headless mirror with modes included, so a TUI that enabled SGR mouse gets its tracking back after a window reload but not its encoding.

Test plan

  • Unit (headless): modes.mouseEncoding set and reset for 1006 and 1016; defaults updated.
  • Playwright (Chromium): the same for the browser Terminal; defaults updated.
  • Playwright (Chromium): SerializeAddon round-trips 1006, 1016, and tracking plus encoding together.
  • npm run test-unit, npm run lint, npm run lint-api.

The mouse encoding (SGR / SGR-pixels) was tracked internally but never
exposed on the public Terminal, so addon-serialize could not restore it:
a serialized terminal came back with mouse tracking intact but the
encoding reset to default.

Add IModes.mouseEncoding alongside mouseTrackingMode, derived from the
same MouseStateService the tracking mode already reads, and emit the
matching DECSET from SerializeAddon.
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.

1 participant