5905 Commits

Author SHA1 Message Date
Anund
600eea08cd testing: point Command.zig at ~more universal external binaries
The `Command.zig` tests reach outside the local source tree and look for
files on the host os machine. This introduces some portability issues
for the tests.

The nix build sandbox doesn't include `/usr/bin/env` making it error out
when `zig build test` runs `Command.zig` tests as part of a `nix build`.
Current ci and local development relies on `nix develop` sharing a host os
file system that includes `/usr/bin/env`.

Turns out `/tmp` and `/bin/sh` are available in the build sandbox in
nix so we swap these in to enable nixpkg builds to include testing
ghostty as part of any update cycle.
2024-12-27 17:07:24 +11:00
Mitchell Hashimoto
a8e5eef11c Fix certain paths in the docs containing spaces when the shouldn't (#3276)
This addresses issue #3275
2024-12-26 19:59:38 -08:00
Joris Guex
73367a55f6 Fix docs formatting 2024-12-27 11:45:42 +08:00
Mitchell Hashimoto
b5f70b834b updated logic for grouping actions (#3262)
Update logic for generating `webgen_actions`. 

Before the change, the following grouping was produced:
```md
## `copy_to_clipboard`
Copy and paste.


## `paste_from_clipboard`
## `paste_from_selection`
## `increase_font_size`
Increase/decrease the font size by a certain amount.
```

After the change, the following grouping is being produced
```md
## `copy_to_clipboard`
## `paste_from_clipboard`
## `paste_from_selection`
Copy and paste.

## `increase_font_size`
## `decrease_font_size`
Increase/decrease the font size by a certain amount.
```

Please note that this is my first time ever writing zig, so forgive me
violating zig best practices and feel free to make suggestions

Successor of [this](https://github.com/ghostty-org/website/pull/147) pr
in the website repo
2024-12-26 19:41:26 -08:00
Mitchell Hashimoto
869987277c Update help comment for backslash (#3173)
Such a little commit, but I banged my head on it for a few minutes!
2024-12-26 19:33:08 -08:00
Felix Salcher
5411c001c8 added doc comment 2024-12-27 04:23:17 +01:00
Felix Salcher
ebfa606c67 updated logic for grouping actions 2024-12-27 04:14:17 +01:00
Anmol Wadhwani
7aced21a8e Use doc comments for focus-follows-mouse 2024-12-27 08:29:35 +05:30
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
Anund
b2cb80dfbb testing: move cleanup of execveZ into the test code 2024-12-27 11:08:45 +11:00
Anund
184db2654c testing: handle execveZ failing during test execution
Duplicating a test process via fork does unexepected things.
zig build test will hang
A test binary created via -Demit-test-exe will run 2 copies of the test suite
2024-12-27 11:08:44 +11:00
Lucas Crownover
6217dbebcf Update help comment for backslash 2024-12-26 14:58:43 -08:00
Mitchell Hashimoto
cd2e2b801a Screen.cursorScrollAboveRotate memory corruption fix (#3129)
Extracted from #3110

Initial fix is relatively basic, and catching it with a test only
required a little bit of extra scrutiny of the cursor state after one of
the tests that we already had.

However, the fix revealed faulty dirty tracking logic throughout the
`cursorScrollAbove` function (and therefore bad results that were being
tested for when they should not have been). I've ended up clarifying
things, fixing the asserted dirty states in all the `cursorScrollAbove`
tests, and then finally implementing another very trivial fix that
catches the mistake.

Fixing the dirty tracking is really just an exercise in correctness
though, since when the scroll happens it inherently invalidates the
viewport, and therefore will trigger a full rebuild in the renderer...
unless, I guess, another operation is performed that cancels things out
and results in the viewport pin being in the same place as the previous
render, but that seems an exceptionally difficult scenario to make
happen on purpose much less accidentally.

This PR is almost entirely changes to comments and tests, there are only
2 lines of real code it changes, the one added to the start of
`cursorScrollAbove` and the one modified at the start of
`cursorScrollAboveRotate`. I believe these changes are entirely safe. (I
wonder if they might have a bad effect on our `vtebench` scrolling
performance though...)
2024-12-26 06:30:27 -08:00
Mitchell Hashimoto
ed8b960ade Screen.cursorAbsolute memory corruption fix (#3127)
Extracted from #3110

A simple fix, with a unit test that covers the issue. This could cause
memory corruption and crashes in fairly realistic scenarios, since it
can occur whenever `cursorAbsolute` is used to move to a page that
happens to be at capacity for some form of managed memory and the cursor
is carrying some managed memory with it (style, hyperlink, etc.).

I really wish Zig had affine types so we could make `cursorChangePin`
"consume" its argument so it can't be accidentally used afterwards... I
think I'll audit the rest of the codebase anywhere we use
`cursorChangePin` to make sure we don't have similar problems.
2024-12-26 06:30:05 -08:00
Tristan Partin
a38acbc11c apprt/gtk: handle nullable event from event controller
gtk_event_controller_get_current_event() is documented to possibly
return NULL.

Fixes: https://github.com/ghostty-org/ghostty/issues/2022
Fixes: https://github.com/ghostty-org/ghostty/issues/3088
Link: https://docs.gtk.org/gtk4/method.EventController.get_current_event.html
Signed-off-by: Tristan Partin <tristan@partin.io>
2024-12-25 23:38:18 -06:00
Qwerasd
d030155c81 fix: unconditionally mark cursor row dirty in cursorScrollAbove
explained in comment
2024-12-25 21:15:58 -05:00
Qwerasd
67f51dcffd test: correct scroll above dirty assertions
Accounts for improved behavior due to prior memory corruption fix for
`cursorScrollAboveRotate` and reveals a new problem in a different
`cursorScrollAbove` sub-function.
2024-12-25 21:14:18 -05:00
Qwerasd
b68c161d98 improve comments
The new diagrams are different due to changes that have happened since
they were last generated.
2024-12-25 21:00:36 -05:00
Qwerasd
6d034d04a0 fix: memory corruption in Screen.cursorScrollAboveRotate
Unless it's guaranteed that the new pin is in the same page as the old
one, `cursor.page_pin` should only be updated through `cursorChangePin`,
not directly.
2024-12-25 20:09:20 -05:00
Qwerasd
a387e680ed test: add additional checks to scroll above cross-page test
Reveals a memory corruption issue caused by the direct assignment of
`cursor.page_pin` instead of using the `cursorChangePin` method.
2024-12-25 20:08:05 -05:00
Qwerasd
8f0dcb9d91 fix: memory corruption in Screen.cursorAbsolute
We call `cursorChangePin` which may invalidate the provided pin if it
needs to adjust the page capacity, and as such we should consider the
pin we pass in to it invalid afterwards, and access it through cursor
instead.
2024-12-25 19:04:35 -05:00
Qwerasd
b89e87c80d test: add failing test for Screen.cursorAbsolute memory corruption 2024-12-25 19:04:35 -05:00
Jan200101
7027147c76 terminal: support progress for ConEmu pause and error state 2024-12-25 14:38:34 -08: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
Mitchell Hashimoto
eacba35d19 terminal: parse ConEmu progress OSC 9 (#3124)
Fixes #3119
Supersedes #3099 

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.

cc @Jan200101
2024-12-25 13:35:13 -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
c3e493f247 config: use escaped encoding for macOS cmd+left/right
Fixes #3114

I forgot that the format gets parsed as a Zig string so putting it in
already parsed made `+list-keybinds` incorrect. It worked either way but
this fixes the `+list-keybinds` CLI action.
2024-12-25 07:06:06 -08:00
David Rubin
8efa638110 optimize Style.eql using PackedStyle 2024-12-25 00:20:06 -08:00
Mitchell Hashimoto
fddedd7c01 feat: add support for middle position quick terminal (#3100)
# Description

This commit introduces the ability to launch the quick terminal in the
middle position.

![Screen Recording 2024-12-24 at 14 59
46](https://github.com/user-attachments/assets/6c733caf-34c7-4e80-ba16-24b41f98d2f0)

## Note to reviewer
- The quick terminal is currently centered. Should we consider adding a
top offset to better align with the screenshot in [the issue](#2494 )?
Should it be configurable?
- On large monitors, half the visible frame might be excessively large.
To mitigate, I am planning to implement #2384 but we should probably
agree on a good default maximum width/height in middle position.
- I also figured out, reloading the configuration does not update the
quick terminal configuration. That is also an issue I will try to fix.

Resolves #2494

I agree to relicense my commit to MIT.
2024-12-24 20:25:38 -08:00
Damien Mehala
44459e93d1 code review 2024-12-25 00:07:12 +01:00
Mitchell Hashimoto
5bb2c62fba config: revert cmd/alt+left/right to legacy encoding on macOS by default
Fixes #3106
Related to #2838
Discussion in #2363

This breaks fixterms encodings for these specific keys so that shells
and other programs that rely on the legacy encoding for these keys will
work by default.

This only does this for macOS because for whatever reason during the
large beta period, only macOS users found this as lacking.

If users want to restore fixterms behaviors, they can rebind these keys
as `unbind`.
2024-12-24 14:48:08 -08:00
Mitchell Hashimoto
44e1c0f397 macos: Make "Settings…" menu item open config file in Application Sup… (#2895)
…port

...unless ~/.config/ghostty/config already exists, then that is opened.
(Or whatever $XDG_CONFIG_HOME points to.)

If both files exists, ghostty reads first the one in
~/.config/ghostty/config and then the one in Application Support, and
merges the settings. In that case, the menu item opens the file at
~/.config.

Fixes #2890.
2024-12-24 12:11:52 -08:00
Mitchell Hashimoto
d7542ec504 terminal: address typos in style struct 2024-12-24 12:08:05 -08:00
David Rubin
5052be3efe add some comments 2024-12-24 10:07:58 -08:00
David Rubin
120a2b9597 optimize Style hashing to be single-shot 2024-12-24 09:35:05 -08:00
Mitchell Hashimoto
67fb7d0bee Fix UB in style hashing by using autoHash, but keep XxHash3
Back out "perf(styles): greatly improve style.hash performance"
This backs out commit 3bfe4cd25ca7a5ae4d4084818b86ada9236b3bb5, but
keeps the hash algorithm as XxHash3 which showed improvements in
performance.
2024-12-24 07:22:31 -08:00
Damien Mehala
1497e90f95 feat: add support for middle position in quick terminal
This update introduces the ability to launch the quick terminal
in the middle position.

Resolves #2494
2024-12-24 14:58:40 +01:00
Mitchell Hashimoto
b1756b93b8 A couple significant performance improvements for styles (#3097)
To preface, I tested the impact of these changes by running
DOOM-fire-zig in a 120x30 window on a ReleaseFast build. I feel that
DOOM-fire-zig is a fairly realistic target when it comes to "high style
use" terminal applications.

1. By adjusting the conditions under which we swap items while inserting
in to our hash table in `RefCountedSet` we can prioritize styles with
many refs, so they're more likely to stay near their target bucket. This
change brought DFZ FPS from ~700 to ~840, or a roughly 20% improvement.
2. By changing how we hash `Style` structs, we can avoid a lot of
unnecessary overhead and benefit from smaller i-cache size as well as
xxHash's better statistical qualities when compared to Wyhash. This
change brought DFZ FPS from ~840 to ~1020, or another roughly 20%
improvement.

These two changes combined represent as roughly 45% improvement over
`main`, which is... pretty good I'd say.

In addition, I've run `vtebench` and there is no significant difference
in the results between this PR and main.
2024-12-23 19:43:47 -08:00
Qwerasd
3bfe4cd25c perf(styles): greatly improve style.hash performance
By switching to one-shot hashing of the raw bytes of the struct with
XxHash3 instead of using `autoHash` with Wyhash, a performance gain of
around 20% can be observed in DOOM-fire-zig.
2024-12-23 22:05:14 -05:00
Qwerasd
56cbbd940b perf(RefCountedSet): make swap metric prioritize high refcount items
This experimentally yields a ~20% performance improvement as measured by
running DOOM-fire-zig, which is honestly a lot more than I expected.
2024-12-23 21:41:51 -05:00
Iain H
415902fe83 apprt/gtk: support dark window decorations with GtkWindow
Add support for the dark GtkWindow variant when `window-theme` is
`dark` or `auto`.
2024-12-23 19:50:57 -05:00
Mitchell Hashimoto
53c41255eb terminal: selectionString only applies x offset on first/last page
Fixes #2841

We were incorrectly applying the start/end x offset for the first/last
row of every single page. If a selection spanned multiple pages this
would trim data incorrectly.

Unit test updated to cover this case.
2024-12-23 14:39:20 -08:00
Mitchell Hashimoto
4f10b13fc3 kittygfx: placement with rows (r) param scrolls properly out of viewport (#3094)
Fixes #2332

Two bugs fixed to fix this behavior:

1. Our destination height didn't account for the top-left being
offscreen.

2. We were using the wrong height for the source rectangle. When a rows
param (r=) is specified, the image height and destination height are at
different scales. We were using the viewport scale for the offset but it
should be the image scale.
2024-12-23 14:16:59 -08:00
Mitchell Hashimoto
bd90a6dd3b kittygfx: placement with rows (r) param scrolls properly out of viewport
Fixes #2332

Two bugs fixed to fix this behavior:

1. Our destination height didn't account for the top-left being
   offscreen.

2. We were using the wrong height for the source rectangle. When a rows
   param (r=) is specified, the image height and destination height are
   at different scales. We were using the viewport scale for the offset
   but it should be the image scale.
2024-12-23 14:11:14 -08:00
Mitchell Hashimoto
cecf2d8699 Fix RefCountedSet issue(s) (#3093)
Fixes #2497 

While investigating the issue I added an integrity check that found a
problem hiding in the insert logic that was unrelated- in fixing that I
greatly simplified the insert logic.

It turns out that #2497 is ultimately just a case of bad luck,
pathological inputs that result in very non-uniform hashes so the
clustering overwhelms things. The solution was just to add a check and
claim we're out of memory.

I tried adding an entropy folding function to fix the hash a little but
it had a measurable negative impact on performance and isn't necessary
so I've not included it here. Currently there's an open PR to Zig to
[add RapidHash](https://github.com/ziglang/zig/pull/22085), which is the
successor to Wyhash and apparently has much better statistical
characteristics on top of being faster. I imagine it will land in time
for 0.14 so whenever we update to 0.14 we should probably switch our
standard hash function to RapidHash, which I imagine should yield
improvements across the board.

Using the AutoHasher may also be not the best idea, I may explore ways
to improve how we generate our style hashes in the future.
2024-12-23 14:10:05 -08:00
Mitchell Hashimoto
0f7a089659 apprt/gtk: move new tab button to start of header bar (#3086)
According to the GNOME human interface guidelines, buttons for the main
user actions, such as new, add, open, and back should be placed at the
start of the header bar.
(https://developer.gnome.org/hig/patterns/containers/header-bars.html#header-bar-buttons)

Moving the new tab button to the start of the header bar brings Ghostty
in line with other GNOME applications such as gedit and gnome-terminal.
2024-12-23 13:30:57 -08:00
Mitchell Hashimoto
809593473b terminal: PageList.pin doesn't allow out of bounds x values
Fixes #2958

The y was alround bounded but we allowed any x value and assumed the
caller would handle it. This is not the case so we now check the x and
return null if it's out of bounds (same as y, which was already doing
this).
2024-12-23 13:27:19 -08:00
Qwerasd
cb60f9d1da fix(RefCountedSet): Gracefully handle pathological cases
Poor hash uniformity and/or a crafted or unlucky input could cause the
bounds of the PSL stats array to be exceeded, which caused memory
corruption (not good!) -- we avoid such cases now by returning an
OutOfMemory error if we're about to insert and there's an item with a
PSL in the last slot.
2024-12-23 16:03:26 -05:00
Mitchell Hashimoto
a908aca563 kittygfx: z-index handling fixes
Fixes #2921

Our z-index handling was pretty much completely broken, hence I can't
think of a better initial commit message. We were splitting the
placements at the wrong points and just generally putting images in the
wrong z-index. I'm shocked this didn't come up earlier.
2024-12-23 12:46:46 -08:00