178 Commits

Author SHA1 Message Date
Mitchell Hashimoto
7aed08be40 terminal: keep track of colon vs semicolon state in CSI params
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.
2025-01-13 12:47:07 -08:00
Damien Mehala
95fc1d64c8 parse ConEmu OSC9;5 2025-01-11 17:24:13 +01:00
Damien Mehala
ead241f38c Merge branch 'main' into dmehala/conemu-osc9 2025-01-05 21:58:45 +01:00
Damien Mehala
d3334ecb06 [3/12] parse ConEmu OSC9;3 2025-01-04 16:19:19 +01:00
Damien Mehala
8d7ed3e0fc feat: parse ConEmu OSC9;2 2025-01-03 00:26:06 +01:00
Damien MEHALA
b52e76334e feat: parse ConEmu OSC9;1 2025-01-01 22:21:47 +01:00
Ayman Bagabas
66681f94e0 fix: handle intermediate bytes in CSI and ESC sequences
This adds missing handling for CSI and ESC commands.

Fixes: https://github.com/ghostty-org/ghostty/issues/3122
2024-12-30 18:26:05 +03:00
Mitchell Hashimoto
3356ce18d1 fix: correct handling of CTC and DECST8C (#3121)
Cursor Tab Control (CTC) `CSI <n> W` has a default value of 0, which is
the same as setting a tab stop at the current cursor position. Set Tab
at every 8th Column (DECST8C) `CSI ? 5 W` is a DEC private sequence that
resets the tab stops to every 8th column.

Reference: https://vt100.net/docs/vt510-rm/DECST8C.html
Reference:
https://wezfurlong.org/ecma48/07-control.html?highlight=ctc#7210-ctc---cursor-tabulation-control
Reference:
https://gitlab.gnome.org/GNOME/vte/-/blob/master/src/parser-seq.py#L596-L601
Fixes: https://github.com/ghostty-org/ghostty/issues/3120
2024-12-25 14:36:22 -08:00
Jan200101
c3bf7246f6 terminal: parse ConEmu progress OSC 9
Fixes #3119

ConEmu and iTerm2 both use OSC 9 to implement different things. iTerm2
uses it to implement desktop notifications, while ConEmu uses it to
implement various OS commands.

Ghostty has supported iTerm2 OSC 9 for a while, but it didn't (and
doesn't) support ConEmu OSC 9. This means that if a program tries to
send a ConEmu OSC 9 to Ghostty, it will turn into a desktop notification.

This commit adds parsing for ConEmu OSC 9 progress reports. This means
that these specific syntaxes can never be desktop notifications, but
they're quite strange to be desktop notifications anyway so this should
be an okay tradeoff.

This doesn't actually _do anything with the progress reports_, it just
parses them so that they don't turn into desktop notifications.
2024-12-25 13:23:21 -08:00
Ayman Bagabas
48368471a7 fix: correct handling of CTC and DECST8C
Cursor Tab Control (CTC) `CSI <n> W` has a default value of 0, which is
the same as setting a tab stop at the current cursor position. Set Tab
at every 8th Column (DECST8C) `CSI ? 5 W` is a DEC private sequence that
resets the tab stops to every 8th column.

Reference: https://vt100.net/docs/vt510-rm/DECST8C.html
Reference: https://wezfurlong.org/ecma48/07-control.html?highlight=ctc#7210-ctc---cursor-tabulation-control
Reference: https://gitlab.gnome.org/GNOME/vte/-/blob/master/src/parser-seq.py#L596-L601
Fixes: https://github.com/ghostty-org/ghostty/issues/3120
2024-12-25 23:40:04 +03:00
Mitchell Hashimoto
039f9231de terminal: parse CSI 22/23 for push/pop title
Related to #2668

This just implements the VT stream parsing. The actual handling of these
events still needs to be done.
2024-11-13 19:49:45 -08:00
Mitchell Hashimoto
e014c68cf0 kitty kbd: progressive enhancement = mode off by one
Fixes #2161
2024-09-03 11:59:25 -07:00
Jeffrey C. Ollie
b11b8be124 Implement Kitty Color Protocol (OSC 21)
Kitty 0.36.0 added support for a new OSC escape sequence for
quering, setting, and resetting the terminal colors. Details
can be found [here](https://sw.kovidgoyal.net/kitty/color-stack/#setting-and-querying-colors).

This fully parses the OSC 21 escape sequences, but only supports
actually querying and changing the foreground color, the background
color, and the cursor color because that's what Ghostty currently
supports. Adding support for the other settings that Kitty supports
changing ranges from easy (cursor text) to difficult (visual bell,
second transparent background color).
2024-08-17 07:05:28 -05:00
Mitchell Hashimoto
ccf62a4960 stylistic nitpicks 2024-08-10 11:03:56 -07:00
Jeffrey C. Ollie
ce5e55d4aa Implement the XTWINOPS (CSI t) control sequences that "make sense".
These sequences were implemented:

CSI 14 t - report the text area size in pixels
CSI 16 t - report the cell size in pixels
CSI 18 t - report the text area size in cells
CSI 21 t - report the window title

These sequences were not implemented because they manuipulate the window
state in ways that we do not want.

CSI 1 t
CSI 2 t
CSI 3 ; x ; y t
CSI 4 ; height ; width ; t
CSI 5 t
CSI 6 t
CSI 7 t
CSI 8 ; height ; width ; t
CSI 9 ; 0 t
CSI 9 ; 1 t
CSI 9 ; 2 t
CSI 9 ; 3 t
CSI 10 ; 0 t
CSI 10 ; 1 t
CSI 10 ; 2 t
CSI 24 t

These sequences were not implemented because they do not make sense in
a Wayland context:

CSI 11 t
CSI 13 t
CSI 14 ; 2 t

These sequences were not implemented because they provide information
about the screen that is unnecessary.

CSI 15 t
CSI 19 t

These sequences were not implemeted because Ghostty does not maintain an
icon title for windows.

CSI 20 t
CSI 22 ; 0 t
CSI 22 ; 1 t
CSI 23 ; 0 t
CSI 23 ; 1 t

These sequences were not implemented because of the additional
complexity of maintaining a stack of window titles.

CSI 22 ; 2 t
CSI 23 ; 2 t
2024-08-07 00:12:20 -05:00
Łukasz Niemier
f9be02a20f chore: clean up typos 2024-08-05 13:56:57 +02:00
Mitchell Hashimoto
c554b607b7 terminal: eraseDisplay should allow kitty erase through
Fixes #1994
2024-08-03 14:05:28 -07:00
Jon Parise
a4bc98a031 terminal: differentiate OSC 133 continuation and secondary kinds
OSC 133 defines distinct continuation (c) and secondary (s) prompt
kinds. They're both treated as prompt continuations but have different
semantic meanings: `c` allows the user to "go back" and edit previous
lines, while `s` does not.

We don't (yet) handle this "editable" distinction, but this change makes
our OSC parser slightly more correct.
2024-07-18 09:09:00 -04:00
Mitchell Hashimoto
245314b14e termio: hook up OSC8 2024-07-05 21:40:38 -07:00
Mitchell Hashimoto
f8e74a563a terminal: parse osc8 end 2024-07-05 21:39:07 -07:00
Mitchell Hashimoto
58173c9df5 terminal: parse osc 8 hyperlink_start 2024-07-05 21:39:06 -07:00
Mitchell Hashimoto
279921b936 terminal: reject invalid DECSASD status code 2024-06-09 21:22:37 -04:00
Mitchell Hashimoto
e2b4ee99e5 terminal: add easy debug mode for stream debugging 2024-06-09 21:22:23 -04:00
Tim Culverhouse
4eddd919ef stream: remove redundant alias handling in csiDispatch
The alias handling block only handles one alias, which is already
handled in the switch statement. Remove this block and rename all
references to 'action' back to 'input'.
2024-06-06 20:15:58 -05:00
Mitchell Hashimoto
9ea78f981e terminal: index (LF) that scrolls scroll region preserves SGR
Fixes #1676

The comment in the diff explains. This is a regression that was not unit
tested properly in the old implementation prior to the paged-terminal
merge.
2024-04-13 21:31:41 -07:00
Qwerasd
5df5fb4a56 fix(terminal/stream): add SPA and EPA handlers 2024-03-28 20:05:10 -04:00
Qwerasd
1c87bf51a0 fix(terminal/stream): correct invalid assertion 2024-03-17 15:06:31 -06:00
Qwerasd
777ecffe6b fix(terminal/stream): fix OOB read and integer overflow 2024-02-08 22:34:21 -05:00
Qwerasd
68c0813397 terminal/stream: Added ESC parsing fast tracks 2024-02-08 21:49:58 -05:00
Qwerasd
f8c544c119 terminal: stream/parser changes 2024-02-07 19:08:34 -05:00
Qwerasd
343cb9a334 fix(terminal): send SI to execute instead of print 2024-02-07 00:14:54 -05:00
Mitchell Hashimoto
fdc67a08f4 terminal: add tests for incomplete utf-8, fix one bug 2024-02-06 08:45:41 -08:00
Qwerasd
689a521256 terminal: remove unused properties 2024-02-06 03:04:00 -05:00
Qwerasd
5769bb16dd fix(terminal): Fix boundary utf-8 decoding crash
Get rid of completePartialUtf8 and simply use the scalar parse (`.next`) to resolve boundary conditions instead.
2024-02-06 02:51:04 -05:00
Mitchell Hashimoto
dc6c52fac1 terminal: do not have the UTF8Decoder overhead if SIMD 2024-02-05 21:26:40 -08:00
Mitchell Hashimoto
449d3b49a4 terminal: split input to fit output chunks 2024-02-05 21:22:27 -08:00
Mitchell Hashimoto
351d9eb402 terminal: use new VT simd to process slices 2024-02-05 21:22:27 -08:00
Mitchell Hashimoto
c751619b7e terminal: use highway-based indexOf to support all targets 2024-02-05 21:22:26 -08:00
Mitchell Hashimoto
62ce93dcff terminal: use SIMD w/ Neon to find ESC in VT streams 2024-02-05 21:22:25 -08:00
Mitchell Hashimoto
0c2a87e5fb terminal: small stylistic tweaks 2024-02-05 21:20:20 -08:00
Qwerasd
846b3421e6 terminal: replace utf8 decoding with custom decoder in stream.zig
(Completely removed utf8 handling from Parser.zig)
2024-02-05 23:20:47 -05:00
Mitchell Hashimoto
3c26828a3f terminal: distinguish between DSRs with "?" and not 2024-02-02 12:42:22 -08:00
Jeffrey C. Ollie
67e347070d fix typo in CSI n handling 2024-02-01 10:50:49 -06:00
Mitchell Hashimoto
c871140419 terminal: handle SCOSC/SCORC
Fixes #1401

SCOSC is ambiguous with regards to DECSLRM. This commit copies the logic
of xterm: if left/right mode is enabled, then CSI S is always DECSLRM.
But if left/right mode is disabled then CSI S empty always uses SCOSC.

SCORC always works.
2024-01-28 08:04:14 -08:00
Mitchell Hashimoto
f445ee269f terminal: ignore change window title requests with invalid UTF-8 2024-01-23 11:52:56 -08:00
Mitchell Hashimoto
adb7958f61 remove tracy usage from all files 2024-01-13 15:06:08 -08:00
Mitchell Hashimoto
84a0e4e62d terminal: support 58;5 for setting underline color via 256 palette
Fixes #1013
2023-12-07 14:57:07 -08:00
Mitchell Hashimoto
8b09764614 terminal: implement OSC 1 (change icon) and ignore it
Fixes #948

We want to parse it so we can log at a lower level than warn but we
don't want to support this because it isn't very well defined.
2023-11-23 14:58:34 -08:00
Mitchell Hashimoto
b5cad7184d terminal: ED handles invalid values 2023-11-19 20:47:04 -08:00
Gregory Anders
3f4ea2f763 core: support OSC 9 and OSC 777 for showing desktop notifications 2023-11-15 10:25:02 -06:00