48 Commits

Author SHA1 Message Date
Mitchell Hashimoto
465ac5b1b7 clean up some of the color usage, use exhaustive switches 2025-07-03 09:25:56 -07:00
Daniel
9e341a3d60 Created tagged union for selection colors, enabled parsing
Implemented cell color for Metal

Removed use of selection-invert-fg-bg

Mirrored feature to OpenGL

Added tests for SelectionColor

Fixed selection on inverted cell behavior

Implemented cell colors for cursor-text

Implemented cell colors for cursor-color, removed uses of cursor-invert-fg-bg during rendering

Updated docs for dynamically colored options

Updated docstrings, cleaned up awkward formatting, and moved style computation to avoid unnecssary invocations

Bump version in docstrings
2025-07-03 07:14:37 -07:00
James Holderness
7f0778bcf2 termio: indicate support for OSC 52 in primary DA report
This is an extension agreed upon by modern terminals to indicate that
they support copying to the clipboard with XTerm's OSC 52 sequence. It
is only reported when writing to the clipboard is actually allowed.
2025-06-29 15:32:17 +01:00
Mitchell Hashimoto
591ef0f40f Move child exit handling logic to apprt thread
Fixes #7500
Supersedes #7582

This commit moves the child exit handling logic from the IO thead to the
apprt thread. The IO thread now only sends a `child_exited` message to
the apprt thread with metadata about the exit conditions (exit code,
runtime).

From there, the apprt thread can handle the exit situation however is
necessary. This commit doesn't change the behavior but it does fix the
issue #7500. The behavior is: exit immediately, show abnormal exit
message, wait for user input, etc.

This also gets us closer to #7649.
2025-06-27 10:36:23 -07:00
Mitchell Hashimoto
1947afade9 input configuration to pass input as stdin on startup
This adds a new configuration `input` that allows passing either raw
text or file contents as stdin when starting the terminal.

The input is sent byte-for-byte to the terminal, so control characters
such as `\n` will be interpreted by the shell and can be used to run
programs in the context of the loaded shell.

Example: `ghostty --input="hello, world\n"` will start the your default
shell, run `echo hello, world`, and then show the prompt.
2025-06-22 18:18:16 -04:00
Mitchell Hashimoto
7e2286eb8c Zig 0.14 2025-03-11 14:39:04 -07:00
Mitchell Hashimoto
d532a6e260 Update libxev to use dynamic backend, support Linux configurability
Related to #3224

Previously, Ghostty used a static API for async event handling: io_uring
on Linux, kqueue on macOS. This commit changes the backend to be dynamic
on Linux so that epoll will be used if io_uring isn't available, or if
the user explicitly chooses it.

This introduces a new config `async-backend` (default "auto") which can
be set by the user to change the async backend in use. This is a
best-effort setting: if the user requests io_uring but it isn't
available, Ghostty will fall back to something that is and that choice
is up to us.

Basic benchmarking both in libxev and Ghostty (vtebench) show no
noticeable performance differences introducing the dynamic API, nor
choosing epoll over io_uring.
2025-02-21 15:04:37 -08:00
Tim Culverhouse
b7009202ce termio: use modified backend
In Termio.init, we make a copy of backend and modify it by calling
initTerminal. However, we used the original in the struct definition.
This lead to the pty being opened with a size 0,0.
2025-02-14 22:44:27 -06:00
Damien Mehala
33b1131a14 fix: selected text remains after clear_screen action
Fixes #3414
2024-12-30 11:03:59 +01:00
moni
250bd35830 termio: clear kitty images when deleting above the cursor 2024-12-08 10:27:15 -08:00
Mitchell Hashimoto
853ba9e3c7 terminal: reset should preserve desired default mode values
Fixes #2857

Some terminal modes always reset, but there are others that should be
conditional based on how the terminal's default state is configured.
Primarily from #2857 is the grapheme clustering mode (mode 2027) which
was always resetting to false but should be conditional based on the
the `grapheme-width-method` configuration.
2024-11-29 14:42:01 -08: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
f16af9de81 termio: need to update cached size on resize 2024-11-15 10:44:02 -08:00
Mitchell Hashimoto
6f62944b9c renderer: message uses new size struct 2024-11-14 13:34:36 -08:00
Mitchell Hashimoto
90c59f2462 termio: change all sizes to the new size type 2024-11-14 13:31:10 -08:00
Mitchell Hashimoto
dcb1ce8377 termio: change resize message to use new size struct 2024-11-14 13:23:24 -08:00
Mitchell Hashimoto
ca8130bec9 core: make surface use only renderer.Size 2024-11-14 13:15:56 -08:00
Mitchell Hashimoto
a436bd0af6 move datastructures to dedicated "datastruct" package 2024-11-07 14:39:10 -08:00
Tim Culverhouse
4f1cee8eb9 fix: report correct screen pixel size
Mode 2048 and CSI 14 t are size report control sequences which contain
the text area size in pixels. The text area is defined to be the extents
of the grid (rows and columns). Ghostty calculates the available size
for the text area by setting the available padding, and then filling as
much of the remaining space as possible. However, if there are remainder
pixels these are still reported as part of the text area size.

Pass the cell_size geometry through so that we can always report the
correct value: columns * cell width and rows * cell height.
2024-10-18 22:29:52 -05:00
Mitchell Hashimoto
e8bbc987e0 termio: stop the termios poller when not focused 2024-09-18 11:56:07 -07: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
Qwerasd
ff6a0bf9a2 termio: wake renderer outside of critical area in resize 2024-08-14 23:46:52 -04:00
Qwerasd
7929e0bc09 fix: prevent flicker while shrinking screen by eliminating thread race
Before this fix, if vsync was on the GPU cells buffer could be cleared
for a frame while resizing the terminal down. This was due to the fact
that the surface sent messages for the resize to both the renderer and
the IO thread. If the renderer thread was processed first then the GPU
cells buffer(s) would be cleared and not rebuilt, because the terminal
state would be larger than the GPU cell buffers causing updateFrame to
bail out early, leaving empty cell buffers.

This fixes the problem by changing the origin of the renderer's resize
message to be the IO thread, only after properly updating the terminal
state, to avoid clearing the GPU cells buffers at a time they can't be
successfully rebuilt.
2024-08-14 19:46:24 -04: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
524f24aaf5 termio: remove unused data 2024-07-15 15:23:39 -07:00
Mitchell Hashimoto
8cd901450a remove unused derived config values 2024-07-15 10:53:01 -07:00
Mitchell Hashimoto
3867e20e72 termio: get rid of manual backend 2024-07-15 10:50:17 -07:00
Mitchell Hashimoto
835d622baa termio: writer => mailbox 2024-07-15 10:23:09 -07:00
Mitchell Hashimoto
001a6d2624 termio: reader => backend 2024-07-15 10:14:14 -07:00
Mitchell Hashimoto
3625e1e58e termio: take reader as option 2024-07-15 09:55:31 -07:00
Mitchell Hashimoto
4a4b9f2411 termio: trying to get Exec to not have access to full Opts 2024-07-15 09:45:58 -07:00
Mitchell Hashimoto
08ed60ceec termio: ReadData is gone! 2024-07-14 15:15:22 -07:00
Mitchell Hashimoto
89d407dd6a termio: excessive cursor reset 2024-07-14 15:13:41 -07:00
Mitchell Hashimoto
a848a53d26 termio: remove a ton of state 2024-07-14 15:10:05 -07:00
Mitchell Hashimoto
af7adedb50 termio: writer abstraction 2024-07-14 14:48:48 -07:00
Mitchell Hashimoto
f50c15c350 termio: ReadData doesn't need a loop 2024-07-14 09:40:53 -07:00
Mitchell Hashimoto
eec33f10e2 termio: remove more unused things 2024-07-13 19:27:17 -07:00
Mitchell Hashimoto
e30e635bed termio: move all subprocess logic to termio.Exec 2024-07-13 19:24:10 -07:00
Mitchell Hashimoto
7c23d61379 termio: rename 2024-07-13 18:50:37 -07:00
Mitchell Hashimoto
b3c2479f87 termio: move subprocess out to its own file 2024-07-13 15:20:38 -07:00
Mitchell Hashimoto
2e62e3354b termio: cleanup more state 2024-07-13 15:19:39 -07:00
Mitchell Hashimoto
bfbbe1485e termio: queueWrite no longer uses EventData 2024-07-13 15:19:38 -07:00
Mitchell Hashimoto
ffaf020576 termio: move stream handler to dedicated file, remove dep on EventData 2024-07-13 15:19:38 -07:00
Mitchell Hashimoto
e51180e4a9 termio: changeConfig on reader data 2024-07-13 15:19:38 -07:00
Mitchell Hashimoto
4e6e0f90c7 termio: remove data field 2024-07-13 15:19:38 -07:00
Mitchell Hashimoto
c4484938c5 termio: wip but it builds 2024-07-13 15:19:38 -07:00