Commit Graph

9623 Commits

Author SHA1 Message Date
Mitchell Hashimoto
eb9faed28b font/sprite: update to z2d 0.12.1, use native path insetting (#13489)
This change updates z2d to 0.12.1 and changes the sprite font path
insetting functionality to use the new path offset abilities released in
the update.

In addition, there has been a slight change to the drawing of E0B5 and
its respective reflection; we now add a 1-pixel horizontal line segment
to each end to force them to be perpendicular. This is because
offsetting pre-expands the curves and ultimately causes the end segments
of the curve itself to have slight non-horizontal angles, which produce
small artifacts at the ends without the forced horizontal ends.
2026-07-27 13:20:50 -07:00
Chris Marchesi
d0e72a3ab6 font/sprite: update to z2d 0.12.1, use native path insetting
This change updates z2d to 0.12.1 and changes the sprite font path
insetting functionality to use the new path offset abilities released in
the update.

In addition, there has been a slight change to the drawing of E0B5 and
its respective reflection; we now add a 1-pixel horizontal line segment
to each end to force them to be perpendicular. This is because
offsetting pre-expands the curves and ultimately causes the end segments
of the curve itself to have slight non-horizontal angles, which produce
small artifacts at the ends without the forced horizontal ends.
2026-07-27 12:08:24 -07:00
Siva Mahadevan
10e6ace6b6 GhosttyI18n: fix build on freebsd with zig 0.16 2026-07-27 12:40:20 -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
1092204df1 config: support unlimited scrollback limits 2026-07-26 20:13:45 -07:00
Mitchell Hashimoto
65c48213b6 config: expose scrollback line limit 2026-07-26 20:13:45 -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
3b4600014c clarify comments 2026-07-26 15:38:19 -07:00
Riccardo Mazzarini
84254a9d8c build: avoid MSVC C++ runtime in no-libcxx builds
AI-assisted: Codex
2026-07-26 15:36:54 -07:00
Riccardo Mazzarini
1fe1b2d23c build: fix static libghostty-vt linking on Windows
This PR fixes static linking for libghostty-vt on Windows by propagating
a couple of missing dependencies (discovered while running Neovim's Zig
build, see
https://github.com/neovim/neovim/actions/runs/30130848061/job/89604799965?pr=39773).
2026-07-26 15:36:54 -07:00
Mitchell Hashimoto
40ab02e338 lib-vt: handle DECRQSS (#13471)
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:21:27 -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
edcb6fb509 memset should match the C ABI (#13469)
The custom memset accepted its fill value as u8 even though C callers
pass int. Accept c_int and explicitly truncate it to the low byte, which
is what other implementations of this do.
2026-07-26 14:49:54 -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
be3d4a5335 terminal: avoid reallocating tabstop storage (#13465)
Avoid redundant tabstop allocation when the current buffer already
satisfies the requested size
2026-07-26 14:43:14 -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
Riccardo Mazzarini
20c3eae04d memset should match the C ABI
The custom memset accepted its fill value as u8 even though C callers
pass int. Accept c_int and explicitly truncate it to the low byte, which
is what other implementations of this do.
2026-07-26 14:33:34 -07:00
Aurelien Brabant
7ee3ac9ec8 refactor: use arena allocator 2026-07-26 17:50:33 +02:00
Aurelien Brabant
0075c75b61 refactor: remove unneeded appendAssumeCapacity 2026-07-26 17:09:52 +02:00
Aurelien Brabant
3024c5d19e refactor: address nits 2026-07-26 16:37:46 +02: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
Aurelien Brabant
88bd4fdcea feat: implement vicinae-hotkey-v1 2026-07-26 05:47:40 +02:00
Jeffrey C. Ollie
f8e13f31e6 Fix desktop detection tests when running from Gnome
Environment variables from the "real" environment leaked into the test
after the Zig 0.16 update which would cause them to fail if you ran them
on a Gnome system.
2026-07-23 14:47:06 -05:00
Mitchell Hashimoto
d65cb5128a build: link libghostty-vt on Apple hosts with native linker
Replaces: https://github.com/ghostty-org/ghostty/pull/13427

Zig's Mach-O linker does not emit LC_ENCRYPTION_INFO_64 for physical
iOS dylibs. This allows libghostty-vt to build successfully but causes
frameworks containing it to fail App Store validation.

I think it'd be cleaner to always just build Apple targets on Apple hosts
with the native linker. We don't need to rely on Zig being correct and 
this helps ensure compatibility for details like this.
2026-07-23 06:41:30 -07:00
Mitchell Hashimoto
30de782e8e fix(terminal): fix kitty temp directory copy length mismatch (#13424)
EDIT:
[exposed](https://github.com/elias8/libghostty/actions/runs/29996356691/job/89171182671?pr=113#step:12:447)
while syncing libghostty dart bindings to latest main.
2026-07-23 06:02:00 -07:00
Jon Parise
e663d54051 os/hostname: switch to std.Io.net.HostName.validate
Zig 0.16's hostname validation routine is RFC 1123-compliant, so we can
use it directly rather than rolling our own.

Ref: efe649b13e
Ref: https://github.com/ziglang/zig/pull/25710
2026-07-23 08:15:06 -04: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
Mitchell Hashimoto
a77c706a18 fix process and global error handling
Restore the error handling that the removed std.posix fork and waitpid
wrappers previously provided. Raw fork failures now propagate, waitpid
retries interruptions before reading status, and edit-config constructs the
sentinel-terminated argv required by execve.

Let global initialization own cleanup through its existing errdefer so
temporary paths are freed once. Report initialization failures with the
static synchronous I/O provider because global I/O has already been torn
down by that point.
2026-07-22 06:33:54 -07:00
Chris Marchesi
7121ab6c3f global: state should default to null 2026-07-21 23:14:34 -07:00
Chris Marchesi
4956668702 vt: get rid of log spam on tests
Zig 0.16.0 made the criteria for reporting "failed command" stricter (or
looser, depending on your perspective I guess...) - now, tests that
print anything to stderr cause the message to appear.

Note that in this instance tests still pass and you get a return code of
0, but nonetheless, it can be confusing.

Additionally, having spammy passing tests in general is not necessarily
a great experience, so this should help with that.

Note that this change was already done to the main tests. We can add a
build argument to control this if need be.
2026-07-21 22:05:33 -07:00
Chris Marchesi
048619a6bf global: take minimal instead of juicy main
The early-stage main Zig wrapper recognizes if main only needs the
minimal state (args and lower-level environment) and skips a bunch of
unneeded initialization (allocator, arena, threaded I/O, and the
higher-level environment map). Particularly, the fact that it does not
set up an I/O instance means that we won't have any unneeded signal
handlers set up for the unused threaded I/O implementation, which is
similar in spirit to the fixes we applied for the C VT implementation,
with the notable difference that we do actually set a threaded I/O up in
global state - hence, again, we don't want the duplicate unused one.
2026-07-21 22:05:33 -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
56b086bd93 terminal: handle page capacity errors in cursorScrollAbove (#13394)
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:16:09 -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
Leah Amelia Chen
2511abe3dd config: update background-blur to reflect growing adoption (#13384)
`ext-background-effect-v1` is finally seeing major adoption throughout
KWin, Mutter, cosmic-comp, Niri, etc. and we should update our comments
on that.
2026-07-20 01:06:58 +08:00
Leah Amelia Chen
2da02f4d28 config: update background-blur to reflect growing adoption
`ext-background-effect-v1` is finally seeing major adoption throughout
KWin, Mutter, cosmic-comp, Niri, etc. and we should update our comments
on that.
2026-07-20 00:34:56 +08:00
Mitchell Hashimoto
c594031d50 terminal: move cursor defaults into terminal state
Cursor defaults were duplicated across stream handlers and it was a
pretty significant amount of simple and yet non-trivial logic to
understand.

Store these on Terminal itself and have methods to route things like
DECSCUSR through for consistent behaviors.
2026-07-17 15:27:34 -07:00
Mitchell Hashimoto
439d35e27c libghostty: mark semantic stream failures
The libghostty-vt stream is made to be infallible: in the case of any error
it just logs and moves on. That's because a terminal can't really... stop,
under normal operations. But, under special operations (fuzzing, replays,
etc.) it can and should stop!

Rather than make the operation fallible, its simply enough for me at least
to know that something went wrong. This is a simple change that adds a simple
flag that is flagged to true when such a scenario happens.

For normal Ghostty GUI operations, this isn't used at all. For libghostty
consumers they can choose to read it if they want, but don't have to.

This also adds a C API to read it.
2026-07-17 12:29:11 -07:00