10552 Commits

Author SHA1 Message Date
Mitchell Hashimoto
891b23917b input: "ignore" binding action are still be processed by the OS/GUI
Related to #7468

This changes the behavior of "ignore". Previously, Ghostty would
consider "ignore" actions consumed but do nothing. They were like a
black hole. Now, Ghostty returns `ignored` which lets the apprt forward
the event to the OS/GUI.

This enables keys that would otherwise be pty-encoded to be processed
later, such as for GTK to show the GTK inspector.
2025-05-29 16:03:03 -07:00
Mitchell Hashimoto
c5e5d61438 terminal: bring alt screen behaviors much closer in line with xterm
This brings the behavior of mode 47, 1047, and 1049 much closer to
xterm's behavior. I found that our prior implementation had many
deficiencies.

For example, we weren't properly copying the cursor state back to the
primary screen from the alternate screen for modes 47 and 1047. And we
weren't saving/restoring cursor state unconditionally for mode 1049 even
if we were already in the alternate screen.

These are weird, edgy behaviors that I don't think anyone expected
(evidence by there being no bug reports about them), but they are bugs
nontheless.

Many tests added.
2025-05-29 15:43:27 -07:00
Mitchell Hashimoto
d94bcda778 build: use a libc txt file to point to correct Apple SDK (#7469)
This fixes an issue where Ghostty would not build against the macOS 15.5
SDK.

What was happening was that Zig was adding its embedded libc paths to
the clang command line, which included old headers that were
incompatible with the latest (macOS 15.5) SDK. Ghostty was adding the
newer paths but they were being overridden by the embedded libc paths.

The reason this was happening is because Zig was using its own logic to
find the libc paths and this was colliding with the paths we were
setting manually. To fix this, we now use a `libc.txt` file that
explicitly tells Zig where to find libc, and we base this on our own SDK
search logic.
2025-05-29 15:20:42 -07:00
Mitchell Hashimoto
0f1860f066 build: use a libc txt file to point to correct Apple SDK
This fixes an issue where Ghostty would not build against the macOS 15.5 SDK.

What was happening was that Zig was adding its embedded libc paths to
the clang command line, which included old headers that were
incompatible with the latest (macOS 15.5) SDK. Ghostty was adding the
newer paths but they were being overridden by the embedded libc paths.

The reason this was happening is because Zig was using its own logic to
find the libc paths and this was colliding with the paths we were
setting manually. To fix this, we now use a `libc.txt` file that
explicitly tells Zig where to find libc, and we base this on our own SDK
search logic.
2025-05-29 15:04:05 -07:00
Jeffrey C. Ollie
d3cb6d0d41 GTK: add action to show the GTK inspector
The default keybinds for showing the GTK inspector (`ctrl+shift+i` and
`ctrl+shift+d`) don't work reliably in Ghostty due to the way Ghostty
handles input. You can show the GTK inspector by setting the environment
variable `GTK_DEBUG` to `interactive` before starting Ghostty but that's
not always convenient.

This adds a keybind action that will show the GTK inspector. Due to
API limitations toggling the GTK inspector using the keybind action is
impractical because GTK does not provide a convenient API to determine
if the GTK inspector is already showing. Thus we limit ourselves to
strictly showing the GTK inspector. To close the GTK inspector the user
must click the close button on the GTK inspector window. If the GTK
inspector window is already visible but is hidden, calling the keybind
action will not bring the GTK inspector window to the front.
2025-05-29 16:07:57 -05:00
Jeffrey C. Ollie
1104993c94 OSC: move some processing back inside the OSC state machine 2025-05-29 11:37:09 -05:00
Jeffrey C. Ollie
f0fc82c80f OSC: account for 32-bit systems in comptime Command size check 2025-05-29 11:37:09 -05:00
Jeffrey C. Ollie
5fb32fd8a0 OSC: add comptime check for size of OSC Command 2025-05-29 11:37:09 -05:00
Jeffrey C. Ollie
bcf4d55dad OSC: nest ColorOperation-related structs 2025-05-29 11:37:08 -05:00
Jeffrey C. Ollie
fa03115f01 OSC: don't use arena during testing 2025-05-29 11:37:08 -05:00
Jeffrey C. Ollie
35384670c4 OSC: fix typo 2025-05-29 11:37:08 -05:00
Jeffrey C. Ollie
e0ddc7a2fa OSC: clean up color_operation handling 2025-05-29 11:37:08 -05:00
Jeffrey C. Ollie
f2dfd9f677 OSC: improve formatting of ColorOperationSource 2025-05-29 11:37:07 -05:00
Jeffrey C. Ollie
bd4d1950ce OSC: remove unused code 2025-05-29 11:37:07 -05:00
Jeffrey C. Ollie
479fa9f809 OSC: use std.SegmentedList instead of custom data structure 2025-05-29 11:37:07 -05:00
Jeffrey C. Ollie
397a8b13e0 OSC: more tests 2025-05-29 11:37:07 -05:00
Jeffrey C. Ollie
1d9d253e4d OSC: fix bug with buffer disappearing 2025-05-29 11:37:07 -05:00
Jeffrey C. Ollie
04e8e52171 OSC: reflow comment 2025-05-29 11:37:06 -05:00
Jeffrey C. Ollie
1288296fdc OSC: add a datastructure to prevent some (most?) allocations 2025-05-29 11:37:06 -05:00
Jeffrey C. Ollie
5bb7492955 OSC: convert OSC 110, 111, and 112 and add more tests 2025-05-29 11:37:06 -05:00
Jeffrey C. Ollie
5ec1c15ecf OSC: add more tests 2025-05-29 11:37:06 -05:00
Jeffrey C. Ollie
9c1abf487e OSC: start adding structure to allow multiple color operations per OSC 2025-05-29 11:37:06 -05:00
Mitchell Hashimoto
b2f3c7f309 fix: properly intialize key event in GlobalEventTap (#7462)
Fixes #7215. The issue was that `GlobalEventTap` didn't fully initialize
the key event before passing it to `ghostty_app_key`. In particular, it
didn't set the `unshifted_codepoint` field, which is needed to find a
match when calling `keybind.set.getEvent`, because `keybind.set` stores
bindings by codepoint, not physical key (i.e., the trigger to match is
`ctrl+p`, not `ctrl+key_p`, et cetera).

The fix was to make `GlobalEventTap` initialize the key event using
`event.ghosttyKeyEvent`, like it's done in `SurfaceView.keyAction` and
`AppDelegate.localEventKeyDown`.

This is my first time touching either Zig or Swift, so I'm a bit green.
In particular, I don't know if it's possible to write a test covering
this, and if so, how and where to put it. Please edit or request changes
as you see fit.
2025-05-29 08:48:10 -07:00
Daniel Wennberg
d1501a4925 fix: properly intialize key event in GlobalEventTap 2025-05-27 22:33:15 -07:00
Mitchell Hashimoto
8a00aa8223 code style: use @splat where possible (#7461)
As of Zig 0.14.0, `@splat` can be used for array types, which eliminates
a lot of redundant syntax and makes things generally cleaner.

I've explicitly avoided applying this change in the renderer files for
now since it would just create rebasing conflicts in my renderer rework
branch which I'll be PR-ing pretty soon.
2025-05-27 21:30:23 -07:00
Qwerasd
6f7e9d5bea code style: use @splat where possible
As of Zig 0.14.0, `@splat` can be used for array types, which eliminates
a lot of redundant syntax and makes things generally cleaner.

I've explicitly avoided applying this change in the renderer files for
now since it would just create rebasing conflicts in my renderer rework
branch which I'll be PR-ing pretty soon.
2025-05-27 21:55:28 -06:00
Mitchell Hashimoto
ad632f1068 Add support for buffer switching with CSI ? 47 h/l (#7443)
This PR adds support for handling the escape sequences CSI ? 47 h/l,
which are related to alternate screen buffer switching. This is in
response to the issue reported in
[ghostty-org/ghostty#7386](https://github.com/ghostty-org/ghostty/issues/7386).

I'm unsure where to add tests for this change. Would it make sense to
add visual tests for this behavior, or is there a preferred approach or
location for testing such functionality? I tested it locally using the
following commands:
```bash
echo -e "\e[?47h"
echo "Printed on the alt screen"
echo -e "\e[?47l"
```
2025-05-27 11:54:28 -07:00
Jonatan Borkowski
21c97aa9d6 add support for buffer switching with CSI ? 47 h/l 2025-05-27 11:48:14 -07:00
Mitchell Hashimoto
d72a1511fe Rework mouse selection logic (#7444)
This PR fixes the problem discussed in #5058 and #7434 by reworking the
selection logic in a way that better handles edge cases as well as being
generally cleaner.

This rework does change how selection behaves slightly, especially
rectangular selection, but the new behavior of rectangular selection is
more in line with other terminals I tested (Terminal.app, Kitty).

There are some TODO comments for adding unit tests- I ran out of steam
tonight, but if this PR is still open tomorrow I'll go ahead and add
them.
2025-05-27 10:12:31 -07:00
Mitchell Hashimoto
ba02f0ae22 decl literal 2025-05-27 09:55:54 -07:00
Qwerasd
6aa84d0e92 test: introduce helper function for mouse selection tests
Removes a lot of repeated code and makes the test cases easier to
understand at a glance.
2025-05-27 09:38:36 -07:00
Qwerasd
4d11673318 unit test mouse selection logic
Adds many test cases for expected behavior of the selection logic, this
will allow changes to be made more confidently in the future without
fear of regressions.
2025-05-27 09:38:36 -07:00
Qwerasd
ecdac8c8c1 terminal: rework selection logic in core surface
This logic is cleaner and produces better behavior when selecting by
dragging the mouse outside the bounds of the surface, previously when
doing this on the left side of the surface selections would include the
first cell of the next row, this is no longer the case.

This introduces methods on PageList.Pin which move a pin left or right
while wrapping to the prev/next row, or clamping to the ends of the row.
These need unit tests.
2025-05-27 09:38:36 -07:00
Qwerasd
58592d3f65 GTK: Don't clamp cursorpos, allow negative values
Other apprts don't do this, so this should be consistent.
2025-05-27 09:38:36 -07:00
Qwerasd
1ce6544945 Wrap comment at 80 cols 2025-05-27 09:38:36 -07:00
Mitchell Hashimoto
04db2f664b Miscellaneous TODOs (#7451)
See commit messages for details.

If some of the commits in this PR have problems with them I'm perfectly
fine with the others being cherry-picked out while the problems are
addressed.

The biggest/broadest reaching changes in this PR come from converting a
lot of code to use decl literals where possible, so there are a lot of
files where only a handful of lines are modified very slightly.
2025-05-27 07:17:45 -07:00
Mitchell Hashimoto
6b1b5ca0e9 nix: update to Nix 25.05 and Zig 0.14.1 (#7447)
Update to Nix 25.05 which gets us GTK 4.18, libadwaita 1.7, and Zig
0.14.1.

Since Nix updated to Zig 0.14.1, the devshell has been switched to Zig
0.14.1 from zig-overlay as well.

Fixes #7305
2025-05-27 07:12:17 -07:00
Mitchell Hashimoto
483cb42088 Correct $XDG_CONFIG_DIR to $XDG_CONFIG_HOME (#7454)
Ghostty doesn't support `$XDG_CONFIG_DIR`, it only supports
`$XDG_CONFIG_HOME`, so the documentation was incorrect. Not to be
confused with `$XDG_CONFIG_DIRS` nor `$XDG_RUNTIME_DIR` (very
consistent…).

Furthermore, `$XDG_CONFIG_HOME` is the correct XDG path:

> <ins>$XDG_CONFIG_HOME</ins> defines the base directory relative to
which user-specific configuration files should be stored. If
<ins>$XDG_CONFIG_HOME</ins> is either not set or empty, a default equal
to <ins>$HOME</ins>/.config should be used.
> […]
> <ins>$XDG_CONFIG_DIRS</ins> defines the preference-ordered set of base
directories to search for configuration files in addition to the
<ins>$XDG_CONFIG_HOME</ins> base directory. The directories in
<ins>$XDG_CONFIG_DIRS</ins> should be separated with a colon ':'.

— [XDG Base Directory Specification § Environment variables][xdgvars]

Cross-reference:
https://github.com/ghostty-org/ghostty/discussions/7431#discussioncomment-13283139.

[xdgvars]:
https://specifications.freedesktop.org/basedir-spec/latest#variables
2025-05-27 07:10:17 -07:00
Kat
468bfce091 Correct $XDG_CONFIG_DIR to $XDG_CONFIG_HOME in theme documentation. 2025-05-27 22:40:01 +10:00
Qwerasd
2384bd69cc style: use decl literals
This commit changes a LOT of areas of the code to use decl literals
instead of redundantly referring to the type.

These changes were mostly driven by some regex searches and then manual
adjustment on a case-by-case basis.

I almost certainly missed quite a few places where decl literals could
be used, but this is a good first step in converting things, and other
instances can be addressed when they're discovered.

I tested GLFW+Metal and building the framework on macOS and tested a GTK
build on Linux, so I'm 99% sure I didn't introduce any syntax errors or
other problems with this. (fingers crossed)
2025-05-26 21:50:14 -06:00
Qwerasd
2fe2ccdbde font/sprite: use decl literals in box drawing code
Cleaner and less visual noise, easy change to make, there are many other
areas in the code which would benefit from decl literals as well, but
this is an area that benefits a lot from them and is self-contained.
2025-05-26 19:56:35 -06:00
Qwerasd
2905b47279 font: use labeled switch continue pattern for feature string parser
In this case it does result in a little repeated code for reading bytes,
but I find the control flow easier to follow, so it's worth it IMO.
2025-05-26 19:39:39 -06:00
Jeffrey C. Ollie
695e0b3e57 nix: temporarily remove snapcraft from the devshell 2025-05-26 11:43:52 -05:00
Jeffrey C. Ollie
48b6807ac9 nix: fix typos 2025-05-26 11:12:30 -05:00
Jeffrey C. Ollie
98309e3226 nix: update to Nix 25.05 and Zig 0.14.1
Update to Nix 25.05 which gets us GTK 4.18, libadwaita 1.7, and Zig 0.14.1.

Since Nix updated to Zig 0.14.1, the devshell has been switched to Zig 0.14.1
from zig-overlay as well.

Fixes #7305
2025-05-26 10:47:43 -05:00
Qwerasd
25a708ed98 terminal/style: compare packed styles directly, no cast needed
Woohoo, Zig 0.14!
2025-05-25 22:53:50 -06:00
Qwerasd
19db2e2755 CircBuf: non-allocating rotateToZero
We can call `std.mem.rotate` for this.
2025-05-25 22:25:23 -06:00
Jeffrey C. Ollie
3f6c02b49e gtk: improve app id validation (#7442)
'g_application_id_is_valid' doesn't allow empty elements or elements
that start with digits.
This commit updates 'isValidAppId' to be more consistant with
'g_application_id_is_valid' avoiding the app id defaulting to 'GTK
Application' for app ids like '0foo.bar' or 'foo..bar'.
2025-05-25 16:11:26 -05:00
alex-huff
113c196078 gtk: use 'gio.Application.idIsValid' instead of 'isValidAppId' 2025-05-25 15:23:13 -05:00
Mitchell Hashimoto
6697dc6642 Add new and update Norwegian split translations (#7423)
This change changes the wording on the split pane functionality. The new
wording is taken from the macOS terminal app when the whole system is
translated to Norwegian.

macOS uses "Del opp vindu" and "Lukk delt vindu" for "Split Pane" and
"Close Split Pane". So instead of using "split" the verb in question is
always "del". Personally I find this translation to be better rooted in
Norwegian.

When looking at the German translation, which is often a good indicator
for Norwegian as well, one can see the same wording being used.
2025-05-25 12:27:40 -07:00