39 Commits

Author SHA1 Message Date
Gregory Anders
eef9664ef8 renderer: track if fg/bg/cursor color is explicitly set by an OSC
The renderer must track if the foreground, background, and cursor colors
are explicitly set by an OSC so that changes are not overridden when the
config file is reloaded.
2024-12-26 20:18:45 -06:00
Gregory Anders
2cbc2833d1 termio: fixes to kitty color reporting
The kitty color report response is an OSC, not a CSI, so change `[` to
`]`. Colors which are unset should be reported with `{key}=`.
2024-11-26 09:01:31 -06:00
Gregory Anders
4042041b61 termio: track whether fg/bg color is explicitly set
Make the foreground_color and background_color fields in the Terminal
struct optional values so that we can determine if a foreground or
background color was explicitly set with an OSC 10 or OSC 11 sequence.
This makes the logic a bit simpler to reason about (i.e.
`foreground_color` is now always "the color set by an OSC 10 sequence"
while `default_foreground_color` is always "the color set by the config
file") and also fixes an issue where an OSC 10 or OSC 11 query would not
report the correct color after a config update changed the foreground or
background color.

The `cursor_color` field was already optional, with the same semantics
(it is only non-null when explicitly set with an OSC 12) so this brings
all three of these fields into alignment.
2024-11-23 19:48:24 -06:00
Mitchell Hashimoto
1c6adf4065 mode 2031 should send updates on any color palette change
Related #2755

From the mode 2031 spec[1]:

> Send CSI ? 2031 h to the terminal to enable unsolicited DSR (device status
> report) messages for color palette updates and CSI ? 2031 l respectively to
> disable it again.
>
> The sent out DSR looks equivalent to the already above mentioned. This
> notification is not just sent when dark/light mode has been changed by the
> operating system / desktop, but also if the user explicitly changed color
> scheme, e.g. by configuration.

My reading of this paired with the original discussion is that this is
meant to be sent out for anything that could possibly change terminal
colors.

Previous to this commit, we only sent out the DSR when the actual system
light/dark mode changed. This commit changes it to send out the DSR on
any operation that _may_ change the terminal colors.

[1]: https://contour-terminal.org/vt-extensions/color-palette-update-notifications/#example-source-code
2024-11-22 13:14:12 -08:00
Mitchell Hashimoto
90c59f2462 termio: change all sizes to the new size type 2024-11-14 13:31:10 -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
edfef1c8df Merge pull request #2662 from ghostty-org/push-zzpqurznxmlq
pwd changed apprt action, macOS app sets proxy icon based on this
2024-11-13 13:37:04 -08:00
Mitchell Hashimoto
3ca246ceb9 apprt: support a pwd change action 2024-11-13 12:29:30 -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
fc7ff2a7ef Merge pull request #2512 from reykjalin/fix-hostname-validation-with-macos-wifi-private-address
Make sure a potential port component is considered during hostname validation for OSC 7 handling and shell integration
2024-11-05 10:40:25 -08:00
Mitchell Hashimoto
4a263f43af stylistic changes 2024-11-05 10:30:56 -08:00
Kristófer R
03bb16fcec Move hostname helpers to src/os/hostname.zig 2024-11-04 16:54:38 -05:00
Kristófer R
3b0a34afbc Extract OSC 7 hostname parsing into helper functions 2024-10-31 21:55:02 -04:00
Kristófer R
3a3da82aa9 Update explanation for number of digits in port number
The explanation now refers to RFC 793 instead of just claiming some
arbitrary value as truth. The previous value was correct, but now there
is a proper source for the correct value.
2024-10-31 18:09:36 -04:00
CJ van den Berg
24f5050484 apprt: also send color_change notifications when colors are reset 2024-10-31 17:52:02 +01:00
Mitchell Hashimoto
1065359b9a apprt: rename set_bg/fg to "color_change" to report all color changes 2024-10-30 16:33:18 -04:00
CJ van den Berg
a2a1d93d5c apprt: propagate OSC10/11 (set term fore/background color) through to apprt
This is to allow the running apprt to set the UI theme to match the
terminal application coloring.
2024-10-30 17:35:34 +01:00
Kristófer R
892dc27896 Make sure a potential port component is considered during hostname validation 2024-10-28 00:50:24 -04:00
Gregory Anders
df06697899 termio: send initial focus reports
When the focus reporting mode (1004) is enabled, send the current focus
state. This allows applications to track their own focus state without
first having to wait for a focus event (or query
it by sending a DECSET followed by a DECRST).

Ghostty's focus state is stored only in the renderer, where the termio
thread cannot access it. We duplicate the focus state tracking in the
Terminal struct with the addition of a new (1-bit) flag. We duplicate
the state because the renderer uses the focus state for its own purposes
(in particular, the Metal renderer uses the focus state to manage
its DisplayLink), and synchronizing access to the shared terminal state
is more cumbersome than simply tracking the focus state in the renderer
in addition to the terminal.
2024-09-04 22:13:52 -05:00
Mitchell Hashimoto
2acd7e8a42 kitty: respond OK with metadata on display transmissions 2024-09-03 11:05:16 -07:00
Mitchell Hashimoto
8e2d63b6fa small stylistic changes 2024-08-24 19:55:09 -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
8df5ec10e3 Merge pull request #2113 from jcollie/osc-21
Implement Kitty Color Protocol (OSC 21)
2024-08-21 09:23:23 -04:00
Mitchell Hashimoto
6bf1acc5a2 terminal: move kitty color structs out to kitty package 2024-08-21 09:18:42 -04:00
Mitchell Hashimoto
9faca303dc termio: move renderer message sending out to separate func 2024-08-21 09:11:20 -04:00
Mitchell Hashimoto
e15db88656 termio: use new formatter, palette helper for kitty color protocol 2024-08-20 23:36:45 -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
Mitchell Hashimoto
18a8d2b01d Minor changes, mainly commenting to clarify some behaviors 2024-08-18 15:05:31 -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
Eduardo Dominguez
2e70ad20df Config: cursor-style can bet set to block_hollow
`cursor-style` can now also be set to `block_hollow`, no other changes
in behaviour are added.
2024-08-16 15:25:44 -06: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
Gregory Anders
b09e4e5d63 config: add cursor-invert-fg-bg option
When set, the cursor-invert-fg-bg option uses the inverted foreground
and background colors of the cursor's current cell to color the cursor,
rather than using a fixed color. This option has higher precedence than
the cursor-color and cursor-text options, but has lower precedence than
an OSC 12 command to change the cursor color.
2024-07-22 08:42:30 -05:00
Mitchell Hashimoto
137ba66211 terminal: implement in-band size reports (Mode 2048)
https://gist.github.com/rockorager/e695fb2924d36b2bcf1fff4a3704bd83
2024-07-17 10:18:15 -07:00
Mitchell Hashimoto
835d622baa termio: writer => mailbox 2024-07-15 10:23:09 -07:00
Mitchell Hashimoto
af7adedb50 termio: writer abstraction 2024-07-14 14:48:48 -07:00
Mitchell Hashimoto
faef40b769 termio: fix up rebase 2024-07-13 15:21:50 -07:00
Mitchell Hashimoto
2e62e3354b termio: cleanup more state 2024-07-13 15:19:39 -07:00
Mitchell Hashimoto
ffaf020576 termio: move stream handler to dedicated file, remove dep on EventData 2024-07-13 15:19:38 -07:00