Commit Graph

8407 Commits

Author SHA1 Message Date
Mitchell Hashimoto
464c31328e terminal: grow prune check should not prune if required for active
Fixes #10352

The bug was that non-standard pages would mix the old
`growRequiredForActive` check and make our active area insufficient in
the PageList.

But, since scrollbars now require we have a cached `total_rows` that our
safety checks always verify, we can remove the old linked list traversal
and switch to some simple math in general across all page sizes.
2026-01-16 21:26:54 -08:00
Mitchell Hashimoto
56237efeef PageList overflow detection and protection (#10337)
Fixes #10258  
Replaces #10284

1. `Page.Capacity` now uses smaller bit-width integers that represent a
true maximum capacity for various fields.
2. On 64-bit systems, a maxed out `Page.Capacity` (every field `maxInt`)
can be represented in an addressable allocation (total required memory
less than 64 bits). This means `Page.layout` can't overflow.
3. All `adjustCapacity` functions replaced with `increaseCapacity` which
doesn't allow specifying the resulting value, which makes it so overflow
is only possible in significantly fewer places, making it easier to
handle in general.
4. `increaseCapacity` can return a new error `OutOfSpace` which happens
when overflow is detected. This means that no valid page can accommodate
the desired capacity increase because we're already at the max. The
caller is expected to handle this.
5. Updated our resize so that the only possible error is system OOM, we
handle the new `OutOfSpace` by copying the recent reflowed row into a
new page and continuing.

A very, very high-level overview is below. The "overflow" here papers
over a bunch of details where the prior usize capacities flowed through
to Page.layout and ultimately RefCountedSet and other managed types
which then caused incorrect calculations on total memory size required.

```mermaid
flowchart TB
    subgraph Before["Before: adjustCapacity"]
        A1[capacity: usize] --> A2["capacity *= 2"]
        A2 --> A3{Overflow?}
        A3 -->|"Not detected"| A4["Massive allocation or crash"]
    end
    
    subgraph After["After: increaseCapacity"]
        B1["capacity: bounded int<br/>(u16/u32)"] --> B2["capacity *= 2"]
        B2 --> B3{Overflow?}
        B3 -->|"OutOfSpace error"| B4["Graceful handling:<br/>move row to new page"]
        B3 -->|"Success"| B5["Normal allocation"]
    end
    
    Before --> After
    
    classDef beforeStyle fill:#3d1a1a,stroke:#ff6b6b,color:#ff6b6b
    classDef afterStyle fill:#1a3d3a,stroke:#4ecdc4,color:#4ecdc4
    
    class A1,A2,A3,A4 beforeStyle
    class B1,B2,B3,B4,B5 afterStyle
```
2026-01-16 14:52:28 -08:00
Mitchell Hashimoto
df35363b15 terminal: more robust handling of max_page_size
not 100%
2026-01-16 14:47:53 -08:00
Mitchell Hashimoto
442a395850 terminal: ensure our std_capacity fits within max page size 2026-01-16 14:25:01 -08:00
Qwerasd
69066200ef fix: handle double tmux control mode exit command 2026-01-16 16:58:58 -05:00
Mitchell Hashimoto
85a3d623b2 terminal: increaseCapacity should reach maxInt before overflow 2026-01-16 13:43:56 -08:00
Qwerasd
4e5c1dcdc1 osc: fix bad indexing for empty kv in semantic prompt 2026-01-16 16:36:37 -05:00
Qwerasd
f89b6433c2 osc: add failing test for osc 133 parsing trailing ;
This actually causes a crash lol, bad indexing of a slice with `1..0`
because it's `key.len + 1 ..` and the length is `0`.
2026-01-16 16:29:59 -05:00
Mitchell Hashimoto
ec0a150098 terminal: moveLastRowToNewPage needs to fix up total_rows 2026-01-16 13:23:55 -08:00
Mitchell Hashimoto
c9d15949d8 terminal: on reflow OutOfSpace, move last row to new page and try again 2026-01-16 13:23:55 -08:00
Mitchell Hashimoto
42321cc7d5 terminal: write to the proper cell 2026-01-16 13:23:55 -08:00
Mitchell Hashimoto
97621ece93 terminal: handle reflowRow OutOfSpace by no-op 2026-01-16 13:23:55 -08:00
Mitchell Hashimoto
25643ec806 terminal: reflowRow extract writeCell 2026-01-16 13:23:55 -08:00
Mitchell Hashimoto
d626984418 terminal: reflowCursor improve error handling on assumed cases 2026-01-16 13:23:55 -08:00
Mitchell Hashimoto
6b2455828e terminal: resizeWithoutReflowGrowCols can only fail for OOM 2026-01-16 13:23:55 -08:00
Mitchell Hashimoto
e704525887 terminal: PageList remove adjustCapacity 2026-01-16 13:23:55 -08:00
Mitchell Hashimoto
b59ac60a87 terminal: remove Screen.adjustCapacity 2026-01-16 13:23:55 -08:00
Mitchell Hashimoto
c8afc42308 terminal: switch to increaseCapacity 2026-01-16 13:09:19 -08:00
Mitchell Hashimoto
25b7cc9f2c terminal: hyperlink state uses increaseCapacity on screen 2026-01-16 13:09:19 -08:00
Mitchell Hashimoto
29d4aba033 terminal: Screen replace adjust with increaseCapacity 2026-01-16 13:09:19 -08:00
Mitchell Hashimoto
1e5973386b terminal: Screen.increaseCapacity 2026-01-16 13:09:19 -08:00
Mitchell Hashimoto
8306f96d94 terminal: PageList.increaseCapacity 2026-01-16 13:07:32 -08:00
Mitchell Hashimoto
95a23f756d terminal: more strict sizing for page capacities, max cap can fit 64-bit 2026-01-16 13:07:32 -08:00
Mitchell Hashimoto
f1dbdc7965 terminal: fix stale cursor pin usage after cursorChangePin
Fixes #10282

The function `cursorChangePin` is supposed to be called anytime the
cursor page pin changes, but it itself may alter the page pin if setting
up the underlying managed memory forces a page size adjustment. 

Multiple callers to this function were erroneously reusing the old page
pin value.
2026-01-16 12:57:29 -08:00
Jon Parise
ca924f4f45 zsh: improve title-related comment 2026-01-16 08:53:18 -05:00
Julian Haag
3ca8b97ca7 fix(zsh): strip control characters from window title
The zsh shell integration was using `${(V)1}` parameter expansion to set
the window title, which converts control characters to their visible
escape sequence representations. This caused commands ending with a
newline to display as `command\n` in the title bar.

Changed to use `${1//[[:cntrl:]]}` which strips control characters
entirely, matching the behavior of the bash integration.
2026-01-16 10:53:50 +01:00
Mitchell Hashimoto
26e243a919 font/shaper/coretext: Detect ligatures to avoid positioning (marking) glyphs incorrectly (#10295)
This PR implements a heuristic for detecting ligatures that then
prevents resetting to the cell grid prematurely, avoiding position
errors from glyphs that follow ligatures. The inspiration for this was
the example from https://github.com/ghostty-org/ghostty/pull/10179 that
was off.

See the giant comment for an explanation of the heuristic.

The tests for this are the following:

### Tai Tham
The Tai Tham example from
https://github.com/ghostty-org/ghostty/pull/10179 got updated since now
the marking glyph is attached to the ligature cell correctly.

Browser:
ᩉ᩠ᨿᩩ

Before:
<img width="970" height="110" alt="CleanShot 2026-01-12 at 10 02 42@2x"
src="https://github.com/user-attachments/assets/1315bbeb-0541-420a-91a1-bac39897efe3"
/>

After:
<img width="962" height="122" alt="CleanShot 2026-01-12 at 10 02 57@2x"
src="https://github.com/user-attachments/assets/ca2b3e1d-0785-462f-993c-f482d875a1e9"
/>

### Javanese

Browser:
ꦤ꧀ꦲꦸ

Before:
<img width="962" height="98" alt="CleanShot 2026-01-12 at 10 05 43@2x"
src="https://github.com/user-attachments/assets/74002334-7140-4646-806e-2194457e56c5"
/>

After:
<img width="962" height="110" alt="CleanShot 2026-01-12 at 10 05 23@2x"
src="https://github.com/user-attachments/assets/49c08ac9-98af-409c-9b0e-49a34da93597"
/>

There does seem to be a small maybe single pixel difference here, and I
didn't investigate why.

### Chakma

Browser:
𑄝𑄖𑄳𑄠𑄬

Before:
<img width="1406" height="104" alt="CleanShot 2026-01-12 at 10 07 52@2x"
src="https://github.com/user-attachments/assets/3ba7a9d8-d2a2-4e47-976a-8c7702462a49"
/>

After:
<img width="1408" height="104" alt="CleanShot 2026-01-12 at 10 08 08@2x"
src="https://github.com/user-attachments/assets/c25c4a41-b651-4109-8ded-69983fc77267"
/>

### Bengali

Browser:
রাষ্ট্রে

Before:
<img width="1370" height="84" alt="CleanShot 2026-01-12 at 10 10 42@2x"
src="https://github.com/user-attachments/assets/c59e5fc9-0e9e-4c8f-b937-025ad28866d2"
/>

After:
<img width="1370" height="96" alt="CleanShot 2026-01-12 at 10 11 00@2x"
src="https://github.com/user-attachments/assets/d108dcda-b0b5-4824-b3e4-d1e2ddb6d6de"
/>

This one doesn't match the browser, but it seems like a CoreText or font
issue.

### Log output

I've got a `log.txt` with 15k lines from "cell_offset.cluster differs
from cluster (potential ligature detected)" logs when I run
[ttylang](https://github.com/jacobsandlund/ttylang) (printing the
Universal Declaration of Human Rights in various languages).

But right now when I try to create a gist with it, I get:

<img width="1554" height="584" alt="CleanShot 2026-01-12 at 10 15 29@2x"
src="https://github.com/user-attachments/assets/b8a5dd0c-c034-45f6-a2fb-80c67f93f26f"
/>
2026-01-15 08:06:07 -08:00
Leah Amelia Chen
916b99df7c terminal: parse kitty text sizing protocol (OSC 66), redux
#9845 redone to use the new OSC parser

Implements the VT side of #5563
2026-01-15 00:13:55 +08:00
Jacob Sandlund
55583d9f27 fix Devanagari test 2026-01-13 10:36:20 -05:00
Jacob Sandlund
0becd6a1e1 Merge remote-tracking branch 'upstream/main' into ligature-detect 2026-01-13 09:48:53 -05:00
Mitchell Hashimoto
c90f47f11f Terminal: keep cross-boundary rows dirty in {insert,delete}Lines (#10290)
This fixes #10265 and thus also the remaining part of #9718 and likely
#10250.

The issue was that when using `insertLines` and `deleteLines` to
generate scrolling in a region that spans a page boundary, rows that are
replaced by a row from a different page lose their dirty flags in the
clone operation, since the flag is part of the data that gets cloned.
The solution is to set the dirty flag again after the clone, just like
the non-cloning branch does after the pointer swap.

**AI disclosure:** Amp is the MVP here. I prompted it with the
hypothesis I developed in #10265 (that this happens when the scrolling
region spans a page boundary), supplemented with insight I gained from
perusing asciicast files (that the offending scrolling operations are
always triggered by `CSI 1 L` or `CSI 1 M`, that is,
`Terminal.insertLines` or `Terminal.deleteLines`). Amp figured out the
rest and drafted the fix and tests. For free!

I cleaned up the tests and then pushed back a bit against the logic
behind the fix, which led to a better understanding and what I think is
a more appropriate fix. I can explain the details if there's interest,
or people can just skim the thread here:
https://ampcode.com/threads/T-019bb0d6-5334-744a-b78a-7c997ec1fade.
2026-01-12 10:21:36 -08:00
Mitchell Hashimoto
136df4a0f5 nix: update nixpkgs, remove zig.hook, and remove x11-gnome (#10286)
As of NixOS/nixpkgs#473413, `zig.hook` no longer supports
`zig_default_flags`, and now they can and must be provided in
`zigBuildFlags` instead.

Updating also requires removing gnome-xorg since it has been removed
from nixpkgs.

`nix flake check` succeeds on my system (x86_64-linux), with a couple
deprecation warnings that I believe aren't important.
2026-01-12 10:20:59 -08:00
MithicSpirit
2af6e255e4 chore: fix typo curor->cursor (2x)
Detected by CI (typos) after nixpkgs update.
2026-01-12 13:17:05 -05:00
Mitchell Hashimoto
5817e1dc5f terminal: PageList can initialize with memory requirements > std 2026-01-12 09:57:20 -08:00
Daniel Wennberg
257aafb7b4 Consolidate dirty marking in insertLines/deleteLines 2026-01-12 09:49:08 -08:00
Mitchell Hashimoto
7ed19689b9 terminal: add Capacity.maxCols 2026-01-12 08:53:34 -08:00
Jacob Sandlund
2a0a575065 comment fixup 2026-01-12 10:22:37 -05:00
Jacob Sandlund
9c6f40680c Merge remote-tracking branch 'upstream/main' into ligature-detect 2026-01-12 09:57:05 -05:00
Jacob Sandlund
f37b0c56ec Keep track of run's max cluster seen. 2026-01-12 09:56:31 -05:00
Daniel Wennberg
095c82910b Terminal: keep cross-boundary rows dirty in {insert,delete}Lines 2026-01-11 23:26:46 -08:00
Daniel Wennberg
87b11e0892 Add failing tests for #10265 2026-01-11 23:25:44 -08:00
Jon Parise
bb1c3bce10 fix(completions.fish): add +help and +version to completions (#10287)
`+help` and `+version` is missing from completions, even though they are
working actions and are referenced in discussion template
[here](https://github.com/ghostty-org/ghostty/pull/7012). This PR adds
the completion for fish (as that is the shell that I use).
2026-01-11 19:45:25 -05:00
Jon Parise
e47272878d extra: enable +help and +version in bash and zsh 2026-01-11 19:26:27 -05:00
Peter Cardenas
2bdbda20fd fix(completions.fish): add +help and +version to completions 2026-01-11 15:29:32 -08:00
Mitchell Hashimoto
b995595953 terminal: tracked pins need to be invalidated for the non-std page
Fixes a regression from #10251

Thanks to @grishy again for finding this. Updated tests to catch it,
too.
2026-01-11 14:25:45 -08:00
Mitchell Hashimoto
24880becb7 terminal: remove the ability to reuse a pool from PageList (#10271)
This was an unused codepath and it complicates some things I'd like to
do, such as resetting our pools during resize. It complicates those
paths because if a user provides a pool we can't reset it (because other
things might be in it). It's best to own the pools. And since we didn't
reuse pools anyway, let's remove that.

Note this was previously used by our old render state mechanism (before
`terminal.RenderState`) as a way for the renderer to speed up clones by
having a preheated pool that was likely the right size before every
frame. Since we changed methods, we don't need it.
2026-01-11 07:23:45 -08:00
Mitchell Hashimoto
6037e2194a terminal: remove the ability to reuse a pool from PageList
This complicates logic and is unused.
2026-01-11 07:18:35 -08:00
rhodes-b
50516ed581 add search selection for GTK 2026-01-10 19:45:05 -06:00
Mitchell Hashimoto
509f073366 terminal: fix up our total row and pin accounting during reuse 2026-01-10 07:11:52 -08:00
Mitchell Hashimoto
235eebfa92 terminal: during test, use the testing allocator for pages 2026-01-10 06:55:24 -08:00