57 Commits

Author SHA1 Message Date
Jan200101
7027147c76 terminal: support progress for ConEmu pause and error state 2024-12-25 14:38:34 -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
Mitchell Hashimoto
e225eb9eff terminal: OSC7 with empty URL resets the pwd to nil
When an empty string is given to OSC7, the pwd is reset to nil (as if
the terminal never received a pwd report to begin with). This is
analogous to how OSC0/2 reset the title to nil when given an empty
string.

This is practically useful for macOS because it allows our proxy icon to
also be reset instead of being stuck on the last known path.

This breaks from any known terminal behavior. As far as I can find, this
is totally unspecified so we're somewhat free to do what we want. I
don't think any terminal programs depend on this behavior, so I think
it's safe to change it.
2024-11-13 13:43:49 -08:00
Mitchell Hashimoto
067a36d67c termio: handle empty titles (OSC 0/2)
Fixes #2651

First, our OSC parser didn't allow blank OSC 0 or 2 requests. This
should be allowed and this fixes that with a test.

Second, it seems many terminals (iTerm2, Kitty) treat setting a blank
title as resetting to whatever the default title is rather than
explicitly setting it as blank. If a program wants a title to be blank
they should send a single space. This commit follows this behavior.
2024-11-13 12:12:43 -08:00
Mitchell Hashimoto
15a9c191d3 terminal: avoid double free by resetting command to non-managed
Fixes a reported macOS crash. Test case shows how its possible.
2024-09-17 13:15:44 -07:00
Mitchell Hashimoto
f4052fd824 terminal: fix uninitialized memory access when kitty color protocol 2024-09-06 14:08:33 -07:00
Mitchell Hashimoto
738a4c568a terminal: do not reset OSC parser if its already empty
This is not a safe operation since the OSC parser has undefined memory
when it is in the empty state. This is on purpose for performance
reasons.
2024-09-05 16:53:34 -07:00
Jeffrey C. Ollie
571988bf99 Clean up Kitty color protocol by using a union
Non-exhaustive enums should be avoided, use a union to
make the code cleaner and safer.
2024-08-21 11:57:27 -05:00
Mitchell Hashimoto
140d1dde5a typos 2024-08-21 09:45:47 -04:00
Mitchell Hashimoto
6bf1acc5a2 terminal: move kitty color structs out to kitty package 2024-08-21 09:18:42 -04:00
Mitchell Hashimoto
e12cfe80b0 terminal: formatter for kitty color protocol kinds 2024-08-20 23:31:34 -04:00
Mitchell Hashimoto
3b2ed40854 terminal: stylistic tweaks to kitty color protocol parsing 2024-08-20 23:21:28 -04:00
Mitchell Hashimoto
f4b2925434 terminal: make kitty color tests a bit more readable 2024-08-20 23:06:09 -04:00
Jeffrey C. Ollie
a2ef0ca751 Address review comments.
- Cap the total number of requests at twice the maximum number of
  keys (currently 263, so 526 requests). Basically you can set and then
  query every key in one message. This is an absurdly high number
  but should prevent serious DOS attacks.
- Clarify meaning of new hex color codes.
- Better handle sending messages to the renderer in a way that should
  prevent deadlocks.
- Handle 0-255 palette color requests by creatively using non-exhautive
  enums.
- Fix an error in the query reply.
2024-08-19 00:22:09 -05:00
Jeffrey C. Ollie
254072e656 fix test error and improve error logging 2024-08-17 15:34:35 -05: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
Łukasz Niemier
f9be02a20f chore: clean up typos 2024-08-05 13:56:57 +02: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
6c7b7843e9 terminal: additional parse test cases 2024-07-05 21:39:07 -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
739fc746bf terminal: OSC parses 4 with empty string param without crashing 2024-02-12 19:30:04 -08:00
Krzysztof Wolicki
0842e572df Update usage of testing.expectEqual 2024-01-04 13:30:34 +01: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
Gregory Anders
3f4ea2f763 core: support OSC 9 and OSC 777 for showing desktop notifications 2023-11-15 10:25:02 -06:00
Gregory Anders
171292a063 core: implement OSC 12 and OSC 112 to query/set/reset cursor color 2023-11-09 16:21:07 -06:00
Gregory Anders
33753f59c8 core: implement OSC 104, 110, and 111 to reset colors 2023-11-09 16:17:21 -06:00
Gregory Anders
1c0b79c40f core: separate default colors from modifiable colors
Default colors are those set by the user in the config file, or an
actual default value if unset. The actual colors are modifiable and can
be changed using the OSC 4, 10, and 11 sequences.
2023-11-09 14:08:14 -06:00
Gregory Anders
006e93bd08 core: implement setting colors with OSC 4, 10, and 11 2023-11-09 11:59:20 -06:00
Gregory Anders
f397353282 core: implement querying with OSC 4 2023-11-09 11:49:06 -06:00
Mitchell Hashimoto
cfac6c4001 terminal: OSC parser takes optional allocator
OSC 52 is the only command that uses this today. If the allocator is
present it will use it to store the clipboard contents.
2023-10-14 21:49:10 -07:00
Tim Culverhouse
5e800df277 osc: allow 0x20-0xFF in osc_put
The osc_string state of the parser limited accepted bytes to 0x7F. When
parsing a utf-8 encoded string as part of an OSC string, the parser
would encounter an error and abort the OSC parsing, allowing any
remaining bytes to be leaked (possibly) as printable characters to the
terminal window.

Allow any byte in the range 0x20 - 0xFF to be accepted by osc_put. Add
test cases which conflict with the 'anywhere' transitions (IE the utf8
sequence includes C1 control codes which might transition to another
state).
2023-09-21 03:08:41 -05:00
Mitchell Hashimoto
19ef4a22a9 terminal: stylistic changes for OSC terminators, 10/11 params 2023-09-14 13:12:41 -07:00
cryptocode
dc14ca86ca Review updates:
* Change state names to more human readable query_default_fg/bg
* Single-line state prongs
* String terminator is not an enum
* Removed `endWithStringTerminator` and added nullabe arg to `end`
* Fixed a color reporting bug, fg/bg wasn't correctly picked
2023-09-14 21:46:23 +02:00
cryptocode
a3696a9185 Implement OSC 10 and OSC 11 default color queries
These OSC commands report the default foreground and background colors.

Most terminals return the RGB components scaled up to 16-bit components, because some
legacy software are unable to read 8-bit components. The PR follows this conventions.

iTerm2 allow 8-bit reporting through a config option, and a similar option is
added here. In addition to picking between scaled and unscaled reporting, the user
can also turn off OSC 10/11 replies altogether.

Scaling is essentially c / 1 * 65535, where c is the 8-bit component, and reporting
is left-padded with zeros if necessary. This format appears to stem from the XParseColor
format.
2023-09-14 21:41:40 +02:00
Mitchell Hashimoto
cb2931cb27 rename cursor shape to mouse shape for OSC 22 2023-09-14 11:12:17 -07:00
Mitchell Hashimoto
ab8569b4bd terminal: parse OSC 22 2023-09-14 09:36:23 -07:00
Mitchell Hashimoto
de3d0b4243 terminal: parse semantic prompt "k" (kind) parameter 2023-09-03 13:47:06 -07:00
Kevin Hovsäter
59fd918443 Allow optional OSC 52 parameter
Quoting from the XTerm documentation:

The first, Pc, may contain zero or more characters from the set c, p, q,
s, 0, 1, 2, 3, 4, 5, 6, and 7. It is used to construct a list of
selection parameters for clipboard, primary, secondary, select, or
cut-buffers 0 through 7 respectively, in the order given. If the
parameter is empty, xterm uses s 0 , to specify the configurable
primary/clipboard selection and cut-buffer 0.

See https://invisible-island.net/xterm/ctlseqs/ctlseqs.html
2023-08-22 14:20:19 +02:00
Mitchell Hashimoto
314f9287b1 Update Zig (#164)
* update zig

* pkg/fontconfig: clean up @as

* pkg/freetype,harfbuzz: clean up @as

* pkg/imgui: clean up @as

* pkg/macos: clean up @as

* pkg/pixman,utf8proc: clean up @as

* clean up @as

* lots more @as cleanup

* undo flatpak changes

* clean up @as
2023-06-30 12:15:31 -07:00
Mitchell Hashimoto
e59b2f7fca terminal: track pwd reported via OSC 7 2023-05-31 18:54:24 -07:00
Mitchell Hashimoto
b538072972 terminal: osc 7 parsing 2023-05-31 17:32:06 -07:00
Mitchell Hashimoto
283c94f874 terminal: parse OSC 133 A redraw like kitty 2023-05-31 15:39:54 -07:00
Mitchell Hashimoto
4047a90555 terminal: track semantic prompt metadata per row 2023-05-27 15:45:51 -07:00
Mitchell Hashimoto
0592e4fa1a terminal: osc parser gracefully handles input data larger than buffer 2022-12-14 21:24:43 -08:00
Mitchell Hashimoto
56de5846f4 OSC 52: Clipboard Control (#52)
This adds support for OSC 52 -- applications can read/write the clipboard. Due to the security risk of this, the default configuration allows for writing but _not reading_. This is configurable using two new settings: `clipboard-read` and `clipboard-write` (both booleans).
2022-11-21 15:12:00 -08:00
Mitchell Hashimoto
02b6eb123e fix test name 2022-11-18 18:18:10 -08:00
Mitchell Hashimoto
dbf167d18a OSC parsing for get/set clipboard (OSC 52) -- not hooked up yet 2022-11-18 18:16:53 -08:00
Mitchell Hashimoto
5c2edf4d2a Fix some stage2 compilation errors 2022-08-17 14:42:23 -07:00
Mitchell Hashimoto
46db4623bc OSC 133;C 2022-06-21 15:50:44 -07:00