Commit Graph

2536 Commits

Author SHA1 Message Date
Mitchell Hashimoto
92c8dfd508 terminal/snapshot: clean up tests 2026-07-30 13:22:15 -07:00
Mitchell Hashimoto
43ec9b373b terminal/snapshot: harden hyperlink decoding, allow invalid hyperlinks for page 2026-07-30 13:07:25 -07:00
Mitchell Hashimoto
b867a0f59e terminal/snapshot: use lib.Enum enums where possible 2026-07-30 12:58:02 -07:00
Mitchell Hashimoto
86ec146334 terminal/snapshot: full encode/decode 2026-07-30 11:24:38 -07:00
Mitchell Hashimoto
83e482700b terminal/snapshot: ready/finish checkpoints 2026-07-30 11:24:38 -07:00
Mitchell Hashimoto
0288bec3cf terminal/snapshot: terminal record 2026-07-30 11:24:37 -07:00
Mitchell Hashimoto
7d91b87766 terminal/snapshot: history record 2026-07-30 11:24:37 -07:00
Mitchell Hashimoto
d34fd0593e terminal/snapshot: screen decoding 2026-07-30 11:24:37 -07:00
Mitchell Hashimoto
f50bdfab20 terminal/snapshot: screen plus active encoding 2026-07-30 11:22:48 -07:00
Mitchell Hashimoto
6508cbbb49 terminal/snapshot: screen record 2026-07-30 11:22:48 -07:00
Mitchell Hashimoto
e8e56e782c terminal/snapshot: small edits 2026-07-30 11:22:47 -07:00
Mitchell Hashimoto
83ffa74e2b terminal/snapshot: page records 2026-07-30 11:22:47 -07:00
Mitchell Hashimoto
406f5e7d82 terminal/snapshot: encode sparse page grids 2026-07-30 11:22:47 -07:00
Mitchell Hashimoto
2fc238ed01 terminal/snapshot: decode directly into pages 2026-07-30 11:22:47 -07:00
Mitchell Hashimoto
d44baa9147 terminal/snapshot: setup the snapshot main 2026-07-30 11:22:47 -07:00
Mitchell Hashimoto
805c3b0baf terminal/snapshot: start page encoding 2026-07-30 11:22:47 -07:00
Mitchell Hashimoto
b4fd26f0d9 terminal/snapshot: hyperlink and style encoding 2026-07-30 11:22:47 -07:00
Mitchell Hashimoto
fdf8dfd7b1 terminal/snapshot: define v0 record framing 2026-07-30 11:22:46 -07:00
Mitchell Hashimoto
4d605bf0d8 Misc improvements for future binary snapshot API (#13525)
Extracted out the raw `src/terminal` changes needed for the future
snapshot work, 4 separate changes. These are uncontroversial and
relatively simple, summarized below. Tests AI assisted but the rest
including commit messages, this PR message, etc. all organic.

* **Add iterator to ref counted set.** Iterate over live entries and
their IDs. Const, doesn't mutate the set.
* **lib.Enum produces stable enums for Zig.** Basically the same as C
except it uses the smallest fitting integer including the holes.
* **PageList: a couple helpers for manually creating pages.** There is
`PageList.Builder` for creating a new pagelist and
`PageList.allocatePage` for modifying an existing one. This allows
PageList construction from raw pages.
2026-07-30 11:21:45 -07:00
Mitchell Hashimoto
457c5a0a64 terminal: PageList align Builder/PageAllocation APIs better
Rename Builder.addPage and PageAllocation.cancel to their consistent allocatePage and deinit forms. Track successful ownership transfers so both builder APIs can use unconditional deferred cleanup without releasing pages transferred to a PageList.
2026-07-30 11:02:12 -07:00
Mitchell Hashimoto
d5c7e54ae4 terminal: fix string capacity check in hyperlink reflow
Fixes #13522

Fixes unreachable when reflow dupes a hyperlink into a destination page 
whose string allocator is nearly full.

The capacity precondition in ReflowCursor.writeCell performed a single
test allocation of `uri.len + id.len` bytes before duping a hyperlink
into the destination page. But PageEntry.dupe allocates the URI and
the explicit ID as two separate allocations, and the string allocator
rounds every allocation up to its 32-byte chunk size independently, so
the two separate allocations can require one more chunk than the
single combined test allocation.

Write a new helper to make sure we get the right amount of space
using the same allocation pattern of dupe.
2026-07-30 09:36:20 -07:00
Mitchell Hashimoto
35db32078b terminal: PageList allocatePage 2026-07-30 07:22:03 -07:00
Mitchell Hashimoto
fc1bd06a1a terminal: PageList builder to build from raw pages 2026-07-29 14:04:39 -07:00
Tim Culverhouse
6c8c07981d terminal: add visibility reports
Applications cannot infer whether an unfocused terminal remains visible, so
focus reports are insufficient for avoiding expensive rendering while a
view is hidden.

Implement private mode 2033 and the visibility query/report sequences.
Track conservative per-surface visibility, report every effective change
while enabled, and always answer explicit queries and mode enables. Keep
view visibility across terminal resets because it is owned by the host,
not terminal state.

Co-authored-by: Amp <amp@ampcode.com>
Amp-Thread-ID: https://ampcode.com/threads/T-019fa965-aa5f-7099-85b4-a9679d2c8bd3
2026-07-28 11:04:13 -05:00
Mitchell Hashimoto
b61fd5fbb6 terminal: add iterator to ref counted set 2026-07-27 13:37:24 -07:00
Jack Pearkes
2729996eab terminal: update event tests for constructor API 2026-07-27 13:19:37 -04:00
Jack Pearkes
628adaf30f terminal: share progress state enum 2026-07-27 13:19:37 -04:00
Jack Pearkes
47d602c422 terminal: expose progress report effect 2026-07-27 12:16:28 -04:00
Jack Pearkes
c3655ba258 terminal: expose desktop notification effect 2026-07-27 12:16:09 -04:00
Mitchell Hashimoto
a27e04e8f9 lib-vt: readers for configured scrollback limits
C API callers could configure runtime scrollback limits but could not
read them back. Add terminal data keys for the primary screen byte and
line configurations.

Return GHOSTTY_NO_VALUE for unlimited limits and keep reads stable while
an alternate screen is active. Document the configured-value semantics
and add focused coverage for defaults, updates, and unlimited values.
2026-07-27 07:14:52 -07:00
Mitchell Hashimoto
03d5fa2689 lib-vt: move scrollback limits to terminal_set
Terminal construction previously accepted GhosttyTerminalOptions with
dimensions and one scrollback byte limit. Remove the options struct from
the ABI and make ghostty_terminal_new accept columns and rows directly.

Add byte and line limit options to ghostty_terminal_set and forward them
to the runtime Terminal setters. NULL removes a limit, while zero bytes
disables scrollback. Update type metadata, tests, and all API examples.
2026-07-27 07:14:40 -07:00
Mitchell Hashimoto
f4c68d65e5 terminal: support runtime scrollback limits
Scrollback limits were fixed when a terminal screen was initialized.
Move byte and line state and enforcement into a shared Limits type so
PageList can update both constraints after initialization and resize.

Add runtime setters to PageList and Terminal. Lowering a limit prunes
eligible history immediately, while zero bytes switches the primary
screen to no-scrollback behavior and clears retained history. Keep
alternate screens unchanged.
2026-07-27 07:02:39 -07:00
Mitchell Hashimoto
739603b8a2 Introduce scrollback-limit-lines to limit scrollback by lines instead of bytes (#13473)
This adds a new config `scrollback-limit-lines` to limit scrollback by
lines instead of bytes. This also renames `scrollback-limit` to
`scrollback-limit-bytes` to make it clear what it does but we have a
compatibility entry so old configurations will continue to work, so its
not breaking.

**This is NOT exclusive to `scrollback-limit-bytes`**. When both are
set, then the _first limit reached_ is used. Since lines is affected by
viewport size and bytes are affected by entries (more styles, more
graphemes, etc.), they serve somewhat different purposes and it might be
useful to set both.

The default remains 50MB of bytes, unlimited lines.

This is not exposed to libghostty yet. I have that coming as a follow up
change.
2026-07-27 05:57:27 -07:00
Mitchell Hashimoto
659a60ae53 terminal/search: fix tests 2026-07-26 20:28:58 -07:00
Mitchell Hashimoto
10bc43420c terminal: make scrollback byte limit optional 2026-07-26 20:13:45 -07:00
Mitchell Hashimoto
86f81fb5b1 terminal: expose scrollback line limit 2026-07-26 20:13:45 -07:00
Mitchell Hashimoto
5b2d3b7df1 terminal: limit scrollback by physical lines 2026-07-26 20:13:45 -07:00
Mitchell Hashimoto
39ae85f040 lib-vt: handle DECRQSS
Move DECRQSS response encoding into the terminal DCS handler so both
the full termio path and libghostty-vt terminal stream emit the same
replies. The C API stream now maintains and releases DCS parser state
and forwards responses through write_pty.
2026-07-26 15:04:16 -07:00
Mitchell Hashimoto
6f10ddfe83 terminal: preserve underline style in DECRQSS (#13470)
DECRQSS previously serialized every active underline as SGR 4, which
caused double, curly, dotted, and dashed styles to round-trip as single
underlines.

Emit the 4:n form for extended underline styles while retaining the
legacy 4 form for single underlines, and cover every supported style.
2026-07-26 14:43:36 -07:00
Mitchell Hashimoto
cb2fef3902 terminal: preserve underline style in DECRQSS
DECRQSS previously serialized every active underline as SGR 4,
which caused double, curly, dotted, and dashed styles to round-trip
as single underlines.

Emit the 4:n form for extended underline styles while retaining the
legacy 4 form for single underlines, and cover every supported style.
2026-07-26 14:35:35 -07:00
Uzair Aftab
5caf20e3e5 terminal: avoid reallocating tabstop storage
Resizing tabstops to an already-supported width previously allocated and
copied an equally sized dynamic buffer because the capacity check
excluded equality. Treat an exactly sized buffer as sufficient, avoiding
the temporary allocation and copy.
Add a fixed-buffer regression test so an unnecessary second allocation
fails the test.
2026-07-26 14:15:17 +02:00
Elias Andualem
960c2cca5d fix: fix kitty temp directory copy length mismatch 2026-07-23 12:22:45 +03:00
Mitchell Hashimoto
b988efcfe5 fix some 0.16 translation regressions 2026-07-22 08:07:06 -07:00
Chris Marchesi
da04b65d4c terminal: init_single_threaded for C API
The C API is assumed to be single-threaded per VT instance.
Additionally, using fully-threaded I/O instances registers signal
handlers, and would do a pair of registrations once per instance, which
could easily get out of hand (and is not really what we intend anyway).

init_single_threaded does not register signal handlers, so it does not
have this issue, and matches the execution model of the C VT API
(single-threaded/not thread-safe within a single VT instance).

This also fixes an initialization issue with the threaded I/O instance
in general (needs allocation as the memory location would have gone out
of scope before).
2026-07-21 21:35:35 -07:00
Mitchell Hashimoto
f2a7652aba mitchell's touchups
- benchmark: avoid buffers to avoid a memcpy
- build: keep frame pointers on macOS. There was some debug changes from
  Zig 0.15 and this helps. Also, Apple actually requires/expects x29 to
  always be a frame pointer.
- build/macos: force libSystem symbols instead of compiler-rt
- global: add InitOpts.tool so that ghostty-gen/bench can parse their
  own actions in `+action`
- quirks: provide our own vectorized memset. see the comment for more
  details why.
- synthetic: fix UB by accessing global.io before it was initialized
- terminal/hash_map: force inline for unique repr types. Zig 0.15
  inlined and 0.16 doesn't, measured a huge slowdown in hyperlink
  benchmarks.
- terminal: add explicit `@Vector` usage for storing a run of identical cells
  as well as for scanning printable cells. This auto-vectorized in Zig
  0.15 but not in Zig 0.16. This produces the same assembly.
- unicode: properties and LUT need power-of-two backing integer to avoid
  bad LLVM codegen
2026-07-21 17:19:16 -07:00
Chris Marchesi
e8525c0fd9 Update to Zig 0.16.0
This commit represents the majority of the work necessary to upgrade
Ghostty to use Zig 0.16.0.

Key parts:

* In addition to its previous responsibilities, the global state now
  houses state for global I/O implementations and the process
  environment. It is now also utilized in the main application along
  with the C library. Where necessary, global state is isolated from key
  parts of the implementation (e.g., in libghostty subsystems), and it's
  expected that this list will grow.

* We currently manage our own C translation layer where necessary. In
  these cases, cImport has been removed in favor of the new external
  translate-c package. Due to fixes that have needed be made to properly
  translate the dependencies that were swapped out, as mentioned, we
  have had to backport fixes from the current translate-c package (and
  the upstream Arocc dependency). We will host this ourselves until Zig
  0.17.0 is released with these fixes.

* Where necessary (only a small number of cases), some stdlib code from
  0.15.2 (and even from 0.17.0) has been taken, adopted, and vendored in
  lib/compat.

Co-authored-by: Leah Amelia Chen <hi@pluie.me>
2026-07-21 12:35:05 -07:00
Mitchell Hashimoto
ee9d5b352f terminal: handle page capacity errors in eraseRow
Re: #13160 (related but not that issue)

PageList eraseRow and eraseRowBounded have the same issue previously
fixed for cursorScrollAbove: when shifting rows up across a page boundary,
the top row of the next page is cloned into the last row of the
previous page, and that clone can fail if the destination page lacks
capacity for the row's managed memory.

Handle the errors the same way the other cross-page copies do:
increase the destination page capacity for the dimension that ran
out and retry the row copy.

This type of logic was repeated EVERYWHERE so I extracted this into a
helper in PageList and Screen. They're slightly different due to the extra
accounting that Screen has to do for the cursor.

Don't know of any scenario this actually happened in the real world but
it was trivially reproducible with tests.
2026-07-20 09:25:37 -07:00
Mitchell Hashimoto
18d8303972 kitty images: add support for transient usage hints (#13389)
Kitty 0.48 added support for usage hints in the image protocol,
specifically for marking images as "transient", meaning that they should
be prioritized for eviction if there is memory pressure.

https://sw.kovidgoyal.net/kitty/graphics-protocol/#image-usage-hints

Also changed the eviction algorithm to use an allocated array for
organizing the images to be evicted rather than using an ArrayList to
minimize the number of allocations made (no real memory savings though).
2026-07-20 08:16:52 -07:00
Mitchell Hashimoto
0433262493 terminal: handle page capacity errors in cursorScrollAbove
Re: #13160

When cursorScrollAbove rotates rows across a page boundary, the last
row of the previous page is cloned into the destination page. That can
cause capacity failures we didn't previously handle.

The error propagated out of the operation after rows had already been rotated, 
leaving the page list half-mutated. Subsequent operations on the corrupted state
can cause crashes since the state was incoherent.

Handle these errors the same way insertLines and deleteLines already
do for their cross-page copies: increase the destination page capacity
for the dimension that ran out and retry the row copy.
2026-07-20 08:03:57 -07:00
Jeffrey C. Ollie
a65e11cc92 kitty images: add support for transient usage hints
Kitty 0.48 added support for usage hints in the image protocol,
specifically for marking images as "transient", meaning that they
should be prioritized for eviction if there is memory pressure.

https://sw.kovidgoyal.net/kitty/graphics-protocol/#image-usage-hints

Also changed the eviction algorithm to use an allocated array for
organizing the images to be evicted rather than using an ArrayList to
minimize the number of allocations made (no real memory savings though).
2026-07-19 23:28:50 -05:00