Commit Graph

13114 Commits

Author SHA1 Message Date
Mitchell Hashimoto
30f189d774 terminal: PageList has page_serial_min 2025-11-26 08:41:26 -08:00
Mitchell Hashimoto
e549af76fe terminal: flattened highlights contain serial numbers for nodes 2025-11-26 08:36:29 -08:00
Mitchell Hashimoto
1786022ac3 terminal: ScreenSearch restarts on resize 2025-11-26 08:31:09 -08:00
Mitchell Hashimoto
8d11335ee4 terminal: PageList stores serial number for page nodes 2025-11-26 08:15:41 -08:00
Mitchell Hashimoto
14abc6a49d search: navigable search results (previous/next) (#9702)
Continuing #189

This adds the `navigate_search:previous` and `next` key bindings which
allow search matches to be navigated. The currently selected search
match is highlighted using a new `search-selected-foreground/background`
configuration with a reasonable default.

As search results are navigated, the viewport moves to keep them
visible.

## Demo



https://github.com/user-attachments/assets/facc9f3e-e327-4c65-b5f7-0279480ac357
2025-11-25 11:13:37 -08:00
Mitchell Hashimoto
7fba2da404 better default search match color 2025-11-25 11:05:38 -08:00
Mitchell Hashimoto
d0334b7ab6 search: scroll to selected search match 2025-11-25 11:05:38 -08:00
Mitchell Hashimoto
ba7b816af0 core: bindings for navigate_search 2025-11-25 11:05:38 -08:00
Mitchell Hashimoto
880db9fdd0 renderer: hook up search selection match highlighting 2025-11-25 11:05:38 -08:00
Mitchell Hashimoto
333dd08c97 search: thread dispatches selection notices, messages 2025-11-25 11:05:38 -08:00
Mitchell Hashimoto
a2a771bb6f search: previous match 2025-11-25 11:05:38 -08:00
Mitchell Hashimoto
c38e098c4c search: fixup selected search when reloading active area 2025-11-25 11:05:38 -08:00
Mitchell Hashimoto
23479fe409 search: select next search match 2025-11-25 11:05:38 -08:00
Mitchell Hashimoto
08f57ab6d6 search: prune invalid history entries on feed 2025-11-25 11:05:38 -08:00
Mitchell Hashimoto
9511b237f3 macOS: fix the animation of showing&hiding command palette (#9698)
https://github.com/user-attachments/assets/0069d634-4156-486f-9b59-141fb4565a19

> [!NOTE]
> AI proofread my comments.
2025-11-25 09:47:12 -08:00
Mitchell Hashimoto
727430c110 benchmarks: align read_buf to cache line (#9700)
This aligns the `read_buf`s in `src/benchmark` to the cache line, so
that we don't leave that alignment up to chance in case it can very
slightly affect the benchmarks.

I ran the before and after on a few of the benchmarks and I don't think
it changes much (data is 200 MiB from `ghostty-gen`):

### codepoint-width

<img width="1738" height="470" alt="CleanShot 2025-11-25 at 09 10 14@2x"
src="https://github.com/user-attachments/assets/f4ea3014-db21-4a4a-8d67-49161829a4b4"
/>

### grapheme-break

<img width="1726" height="470" alt="CleanShot 2025-11-25 at 09 10 51@2x"
src="https://github.com/user-attachments/assets/d99d220b-3221-4adc-b7f5-58c7b86765bb"
/>

### is-symbol

<img width="1654" height="466" alt="CleanShot 2025-11-25 at 09 11 09@2x"
src="https://github.com/user-attachments/assets/d55e6c12-a650-49cc-aee9-b887eccd42dd"
/>

AI: no AI, just a simple replace.
2025-11-25 09:46:25 -08:00
Jacob Sandlund
807febcb5e benchmarks: align read_buf to cache line 2025-11-25 09:07:21 -05:00
Lukas
2a627a4665 macOS: fix the animation of showing&hiding command palette 2025-11-25 11:22:14 +01:00
Mitchell Hashimoto
94e52ffcfb pkg/{highway,simdutf}: disable ubsan (#9696)
This causes linker issues for some libghostty users. I don't know why we
never saw these issues with Ghostty release builds, but generally
speaking I think its fine to do this for 3rd party code unless we've
witnessed an issue. And these deps have been stable for a long, long
time.
2025-11-24 21:23:11 -08:00
Mitchell Hashimoto
ee5dde795a fix(renderer): load linearized fg color for cursor cell (#9695)
It's clear from the surrounding code that the RGB values returned from
`cell_text_vertex` are expected to be linearized. This was not the case
for the cursor cell, resulting in the cursor text being too bright when
using `cursor-text = cell-background`.

Fixes #8353/#9138.

xref #8960, which would also fixe this issue, but I don't know where
that's heading
2025-11-24 21:22:02 -08:00
Mitchell Hashimoto
c92a003325 pkg/{highway,simdutf}: disable ubsan
This causes linker issues for some libghostty users. I don't know why we
never saw these issues with Ghostty release builds, but generally
speaking I think its fine to do this for 3rd party code unless we've
witnessed an issue. And these deps have been stable for a long, long
time.
2025-11-24 21:18:49 -08:00
Daniel Wennberg
d31be89b16 fix(renderer): load linearized fg color for cursor cell 2025-11-24 21:04:54 -08:00
Mitchell Hashimoto
6f0927c42a Search binding, viewport rendering (#9687)
The march towards #189 continues.

This hooks up the search thread to the main surface and all the state
necessary for the renderer to show search results in the viewport! This
also adds a `search` binding which takes a query to start/stop a search.
**This still doesn't add any search GUI,** which will come later, the
internals must happen first.

A non-blank binding will start or change the search term. An empty
binding will stop search:

```
keybind = cmd+f=search:Hello
keybind = shift+cmd+f=search:
```

> [!NOTE]
>
> Obviously, search will eventually have a GUI. The point of this PR is
primarily to connect all the various internal systems more than
anything. GUI will come soon.

## Demo


https://github.com/user-attachments/assets/06af5a3b-280e-4804-b506-419b92a95f99

## Major Changes

The only major changes required as part of this is the introduction of
what I'm calling the terminal "highlight" system. This is a generic
system for highlighting portions of the terminal contents. These will
ultimately underpin what we currently call "selections" (selecting text
with your mouse/keyboard) but that is far too large a change to make in
one PR.

Therefore, this PR introduces highlights and the only consumer is the
entire search subsystem.

## Limitations

Still plenty of limitations we need to keep marching towards resolving:

- ~~Search matches are styled the same as selections. They should be
different.~~
- There is no way to iterate search matches, yet.
- There is no GUI for inputting a search query or viewing total matches,
yet.
- ~~I think searches are case-sensitive currently and they should
probably not be.~~ Done, for ASCII.

But hey, it's something!
2025-11-24 20:32:06 -08:00
Mitchell Hashimoto
bb21c3d6b3 search: case-insesitive (ascii) search 2025-11-24 20:25:26 -08:00
Mitchell Hashimoto
de16e4a92b config: add selection-foreground/background 2025-11-24 20:16:01 -08:00
Mitchell Hashimoto
a4e40c7567 set proper dirty state to redo viewport search 2025-11-24 19:55:27 -08:00
Mitchell Hashimoto
06981175af renderer: reset search dirty state after processing 2025-11-24 19:55:27 -08:00
Mitchell Hashimoto
d0e3a79a74 reset search on needle change or quit 2025-11-24 19:55:27 -08:00
Mitchell Hashimoto
dd9ed531ad render viewport matches 2025-11-24 19:55:27 -08:00
Mitchell Hashimoto
6c8ffb5fc1 renderer: receive message with viewport match selections
Doesn't draw yet
2025-11-24 19:55:27 -08:00
Mitchell Hashimoto
061d157b50 terminal: search should use active area dirty tracking 2025-11-24 19:55:27 -08:00
Mitchell Hashimoto
72921741e8 terminal: search.viewport supports dirty tracking for more efficient 2025-11-24 19:55:27 -08:00
Mitchell Hashimoto
e49f4a6dbc search binding action starts a search thread on surface 2025-11-24 19:55:27 -08:00
Mitchell Hashimoto
6623c20c2d terminal: switch search to use flattened highlights 2025-11-24 19:55:27 -08:00
Mitchell Hashimoto
05d6315e82 terminal: add a SlidingWindow2 that uses highlights 2025-11-24 19:55:27 -08:00
Mitchell Hashimoto
ec5bdf1a5a terminal: highlights 2025-11-24 19:55:27 -08:00
Mitchell Hashimoto
56b69ff0fd datastruct: make CircBuf use the assumeCapacity pattern 2025-11-24 19:55:27 -08:00
Mitchell Hashimoto
54370c22ba renderer: use proper cell style for cursor-color/text (#9694)
Regression from render state work.
2025-11-24 19:55:14 -08:00
Mitchell Hashimoto
878ccd3f34 renderer: use proper cell style for cursor-color/text
Regression from render state work.
2025-11-24 19:52:21 -08:00
Mitchell Hashimoto
a7d5a5a20e Fix pkg/freetype LoadFlags struct to correctly match FreeType API (#9691)
The struct was missing padding at bit position 8, causing all subsequent
flag fields (bits 9+) to be misaligned by one bit position.

See:
https://freetype.org/freetype2/docs/reference/ft2-glyph_retrieval.html#ft_load_xxx
2025-11-24 19:35:58 -08:00
Qwerasd
6d65abc489 fix(pkg/freetype): fully correct load flags
These now properly match the FreeType API- compared directly in the unit
tests against the values provided by the FreeType header itself.

This was ridiculously wrong before, like... wow.
2025-11-24 17:57:02 -07:00
Qwerasd
3cd6939af6 pkg/freetype: add failing unit tests for LoadFlags 2025-11-24 17:35:53 -07:00
Qwerasd
6a9c869f9d Partially revert 25856d6 since it broke pkg/freetype tests 2025-11-24 17:24:47 -07:00
Pyry Takala
5bfeba6603 Fix LoadFlags struct bit alignment to match FreeType API
The struct was missing padding at bit position 8, causing all subsequent flag fields (bits 9+) to be misaligned by one bit position.

See: https://freetype.org/freetype2/docs/reference/ft2-glyph_retrieval.html#ft_load_xxx
2025-11-24 23:34:47 +00:00
Mitchell Hashimoto
8278718c57 Fix LangSet.hasLang() to compare against FcLangEqual instead of FcTrue (#9685)
FcLangSetHasLang returns FcLangResult enum values:
- FcLangEqual (0): Exact match
- FcLangDifferentTerritory (1): Same language, different territory
- FcLangDifferentLang (2): Different language
See also
https://www.freedesktop.org/software/fontconfig/fontconfig-devel/fclangsethaslang.html
and
https://codebrowser.dev/qt6/include/fontconfig/fontconfig.h.html#_FcLangResult

The previous comparison to FcTrue (1) caused:
- Exact matches (0) to incorrectly return false
- Partial matches (1) to incorrectly return true

This fix changes the comparison to FcLangEqual (0) so hasLang()
correctly returns true only for exact language matches.
2025-11-24 13:13:51 -08:00
Pyry Takala
d4c2376c2d Fix LangSet.hasLang() to compare against FcLangEqual instead of FcTrue
FcLangSetHasLang returns FcLangResult enum values:
- FcLangEqual (0): Exact match
- FcLangDifferentTerritory (1): Same language, different territory
- FcLangDifferentLang (2): Different language

The previous comparison to FcTrue (1) caused:
- Exact matches (0) to incorrectly return false
- Partial matches (1) to incorrectly return true

This fix changes the comparison to FcLangEqual (0) so hasLang()
correctly returns true only for exact language matches.

Fixes emoji font detection which relies on checking for 'und-zsye'
language tag support.
2025-11-24 20:34:07 +00:00
Mitchell Hashimoto
b5dfe5dbfe Add GHOSTTY_QUICK_TERMINAL for quick terminal detection (#9673)
## Summary

Adds a new environment variable `GHOSTTY_QUICK_TERMINAL=1` that is set
when a terminal surface is launched as a quick terminal. This allows
shell configurations to conditionally adjust behavior based on whether
the terminal is a quick terminal.

Closes #3985

<img width="1430" height="228" alt="CleanShot 2025-11-23 at 12 39 27
png"
src="https://github.com/user-attachments/assets/1085c19b-9d58-4603-a03d-662bfde47095"
/>

## Motivation

Quick terminals are designed as ephemeral, singleton windows for quick
commands. Many users (especially tmux users) have shell configurations
that automatically attach to or start tmux sessions on terminal launch.
This automatic behavior conflicts with the quick terminal use case.

Example from the issue:
```zsh
# Users want to skip this in quick terminals
if [[ -z "$TMUX" ]]; then
  tmux attach || tmux new
fi

With this PR, users can now detect quick terminals and adjust their shell behavior:
if [[ -z "$TMUX" ]] && [[ -z "$GHOSTTY_QUICK_TERMINAL" ]]; then
  tmux attach || tmux new
fi
```

## Implementation

- macOS: Added GHOSTTY_QUICK_TERMINAL=1 to SurfaceConfiguration
environment variables in QuickTerminalController.swift:345-351
- Linux/GTK: Added environment variable check in
src/apprt/gtk/class/surface.zig:1469-1472 within defaultTermioEnv()

 The environment variable is automatically inherited by split surfaces.

## Note on Scripting API

I'm aware that @rhodes-b mentioned this functionality was planned for
the scripting API (issue #3985). However, I believe this simpler
environment variable approach provides immediate value for tmux users
and shell configuration use cases, while the scripting API can later
provide more comprehensive surface introspection capabilities.

## AI Assistance Disclosure

This PR was written with Claude Code assistance. The Linux/GTK
implementation was fully AI-generated. I implemented the mac version
myself after Claude Code helped me understand the codebase architecture
and locate the appropriate files.
2025-11-24 08:21:21 -08:00
Mitchell Hashimoto
98e7c17fcc unicode: fix VS15/VS16 check to consider emoji bases (#9679)
This PR builds on https://github.com/ghostty-org/ghostty/pull/9678 ~so
the diff from there is included here (it's not possible to stack PRs
unless it's a PR against my own fork)--review that one first!~

This PR fixes an issue with the VS15/VS16 handling in terminal `print`,
where before we didn't check for valid sequences if the base code point
is an emoji. This meant that a VS15 after an emoji that isn't part of a
valid sequence would narrow the cell, despite that the emoji doesn't
have a text presentation.

This PR also uses a single `is_emoji_vs_base` instead of the
`is_emoji_vs_emoji` and `is_emoji_vs_text`. See the [uucode
comment](215ff09730/src/config.zig (L239-L254))
for why I'm recommending this.

AI was used in some of the uucode changes in
https://github.com/ghostty-org/ghostty/pull/9678 (Amp--primarily for
tests), but everything was carefully vetted and much of it done by hand.
This PR was made without AI.
2025-11-24 08:20:07 -08:00
Jacob Sandlund
a0203e8d1a Merge remote-tracking branch 'upstream/main' into vs-correctness 2025-11-24 10:47:22 -05:00
Mitchell Hashimoto
38fbbba8e9 deps: Update uucode to latest (#9678)
This updates uucode to the latest version, with the following changes:
b309dfb4e2...31655fba3c

For this PR, the new `uucode` version has two changes that contribute to
the diff:

* The `grapheme_break` now includes `emoji_modifier` and
`emoji_modifier_base`, so we don't need to grab those from
`is_emoji_modifier` and `is_emoji_modifier_base`.
* The `wcwidth` calculation has been split into `wcwidth_standalone`
(width of a code point when it's the only code point in a grapheme) and
`wcwidth_zero_in_grapheme` (whether the code point is _not_ contributing
to the width of a multi-code-point grapheme). To keep the current
Ghostty behavior for this PR, this sets `width` to 0 if
`wcwidth_zero_in_grapheme`, but with the exception of
`is_emoji_modifier` (see comment).
* While this PR isn't affected by it, take a look at
[wcwidth.zig](https://github.com/jacobsandlund/uucode/blob/main/src/x/config_x/wcwidth.zig)
for the considerations that went into determining the width of a code
point, along with many comments.
* See
[x/grapheme.zig](https://github.com/jacobsandlund/uucode/blob/main/src/x/grapheme.zig)
for the calculation of the width of a grapheme based on the width of the
code points with exceptions, again with many comments.
* See
[resources/wcwidth](https://github.com/jacobsandlund/uucode/tree/main/resources/wcwidth)
for a comparison of other unicode libraries calculation of "wcwidth".

PRs will follow this in a moment to also take advantage of the new
`uucode` version for:

* Better grapheme segmentation
* Correct VS15/VS16 handling
* More correct cell width calculation (especially certain scripts such
as Devanagari)
2025-11-24 07:31:22 -08:00