Skip to content

Fix SGR handler treating prefixed CSI sequences (e.g. XTMODKEYS) as SGR - #232

Open
smohekey wants to merge 1 commit into
TerminalStudio:masterfrom
smohekey:fix/sgr-ignore-private-prefix
Open

Fix SGR handler treating prefixed CSI sequences (e.g. XTMODKEYS) as SGR#232
smohekey wants to merge 1 commit into
TerminalStudio:masterfrom
smohekey:fix/sgr-ignore-private-prefix

Conversation

@smohekey

Copy link
Copy Markdown

Problem

EscapeParser._csiHandleSgr runs for any CSI ending in m, ignoring the private prefix that was parsed into _csi.prefix. Real SGR is CSI Ps m and never carries a prefix, but several sequences share the m final byte while carrying a prefix and are not SGR — most notably XTMODKEYS CSI > Ps ; Ps m (set modifyOtherKeys), which many terminals and TUI apps emit on startup/attach.

Because the handler reads such a sequence's parameters as SGR codes, CSI > 4 ; 2 m (\e[>4;2m) is interpreted as SGR 4 (underline on) + 2 (faint), so the entire screen becomes underlined until something resets it.

Reproduce

final terminal = Terminal();
terminal.write('\x1b[>4;2m'); // XTMODKEYS, not SGR
terminal.write('hello');
// expected: no underline
// actual:   terminal.cursor.isUnderline == true  ->  'hello' underlined

This is easy to miss because the sequence is often split across read chunks and only emitted on some attaches, so it presents as intermittent.

Fix

Bail out of _csiHandleSgr when the CSI has a private prefix, so only genuine CSI Ps m toggles graphic rendition. Genuine underlining is unaffected — verified \e[4m / \e[24m and combined \e[4;38;5;208m still render underline correctly.

`_csiHandleSgr` runs for any CSI ending in `m`, ignoring the private prefix.
Real SGR is `CSI Ps m` and never has a prefix, but sequences that share the `m`
final byte and carry a prefix are not SGR — notably XTMODKEYS
`CSI > 4 ; 2 m` (set modifyOtherKeys), which many terminals and TUI apps emit on
startup. Because the handler read its parameters `[4, 2]` as SGR codes, `4`
switched on underline for every following cell — the whole screen appears
underlined until reset.

Bail out of the SGR handler when the CSI has a private prefix so only genuine
`CSI Ps m` toggles graphic rendition. Verified `\e[4m` / `\e[24m` and combined
sequences like `\e[4;38;5;208m` still render underline correctly.
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