Skip to content

Conversation

@mitchellh
Copy link
Contributor

Fixes #5022

The CSI SGR sequence (CSI m) is unique in that its the only CSI sequence that allows colons as delimiters between some parameters, and the colon vs. semicolon changes the semantics of the parameters.

Previously, Ghostty assumed that an SGR sequence was either all colons or all semicolons, and would change its behavior based on the first delimiter it encountered.

This is incorrect. It is perfectly valid for an SGR sequence to have both colons and semicolons as delimiters. For example, Kakoune sends the following:

;4:3;38;2;175;175;215;58:2::190:80:70m

This is equivalent to:

  • unset (0)
  • curly underline (4:3)
  • foreground color (38;2;175;175;215)
  • underline color (58:2::190:80:70)

This commit changes the behavior of Ghostty to track the delimiter per parameter, rather than per sequence. It also updates the SGR parser to be more robust and handle the various edge cases that can occur. Tests were added for the new cases.

Fixes #5022

The CSI SGR sequence (CSI m) is unique in that its the only CSI sequence
that allows colons as delimiters between some parameters, and the colon
vs. semicolon changes the semantics of the parameters.

Previously, Ghostty assumed that an SGR sequence was either all colons
or all semicolons, and would change its behavior based on the first
delimiter it encountered.

This is incorrect. It is perfectly valid for an SGR sequence to have
both colons and semicolons as delimiters. For example, Kakoune sends
the following:

    ;4:3;38;2;175;175;215;58:2::190:80:70m

This is equivalent to:

  - unset (0)
  - curly underline (4:3)
  - foreground color (38;2;175;175;215)
  - underline color (58:2::190:80:70)

This commit changes the behavior of Ghostty to track the delimiter per
parameter, rather than per sequence. It also updates the SGR parser to
be more robust and handle the various edge cases that can occur. Tests
were added for the new cases.
@mitchellh mitchellh enabled auto-merge January 13, 2025 20:53
@mitchellh mitchellh merged commit 592efb4 into main Jan 13, 2025
60 checks passed
@mitchellh mitchellh deleted the push-vktoxvosptny branch January 13, 2025 21:00
@github-actions github-actions bot added this to the 1.1.0 milestone Jan 13, 2025
@jerch
Copy link

jerch commented Sep 23, 2025

In your recent blog article about libghostty you say:

And I still haven't found a single web console that renders this complex style sequence correctly.

I guess that most webconsoles use xterm.js under the hood. As far as I know, there is nothing wrong in xterm.js with mixing colon and semicolon notation in SGR, this is supposed to work since colon notation got implemented. If there is indeed an issue, plz let us know. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants