Commit Graph

9177 Commits

Author SHA1 Message Date
Mitchell Hashimoto
e157dd69c5 build: add pkg-config static linking support and fat archives to libghostty
The libghostty-vt pkg-config file was missing Libs.private, so
pkg-config --libs --static returned the same flags as the shared
case, omitting the C++ standard library needed by the SIMD code.

Additionally, the static archive did not bundle the vendored SIMD
dependencies (simdutf, highway, utfcpp), leaving consumers with
unresolved symbols when linking. If we're choosing to vendor (no -fsys)
then we should produce a fat static archive that includes them. If `-fsys`
is used, then we should not bundle them and instead reference them via
Requires.private, letting pkg-config chain to their own .pc files.

Add Libs.private with the C++ runtime (-lc++ on Darwin, -lstdc++
on Linux) and Requires.private for any SIMD deps provided via
system integration. When SIMD deps are vendored (the default),
produce a fat static archive that bundles them using libtool on
Darwin and ar on Linux. When they come from the system (-fsys=),
reference them via Requires.private instead, letting pkg-config
chain to their own .pc files.
2026-04-04 06:54:42 -07:00
Lukas
18f2702225 macOS: fix Find Next/Previous button in the menu bar is not working as expected 2026-04-02 20:31:31 +02:00
Lukas
c8702ece8f gtk(chore): fix typos
### AI Disclosure

Claude wrote the regex to ignore base64-encoded sequences
2026-04-01 13:08:55 +02:00
Jeffrey C. Ollie
c2dd7579e2 core/gtk: ensure that first surface gets marked as focused surface by app (#12029) 2026-03-31 15:29:18 -05:00
Jeffrey C. Ollie
4b5f2d60e7 core/gtk: ensure that first surface gets marked as focused surface by app 2026-03-31 14:57:41 -05:00
Jeffrey C. Ollie
dee8598dc0 gtk: use surface id for notifications instead of pointer 2026-03-31 14:53:19 -05:00
Jeffrey C. Ollie
ff02ed1b34 core: add 64 bit unique ID to every core surface
- Expose that ID as the environment variable GHOSTTY_SURFACE_ID to
  processes running in Ghostty surfaces.
- Add a function to the core app to search for surfaces by ID.
- ID is randomly generated, it has no other meaning other than as a
  unique identifier for the surface. The ID also cannot be zero as that
  is used to indicate a null ID in some situations.
2026-03-31 13:13:05 -05:00
Mitchell Hashimoto
4803d58bb4 apprt/embedded: fix ghostty_surface_free_text parameter mismatch
Fixes #12020

The C header declared ghostty_surface_free_text with both a
ghostty_surface_t and ghostty_text_s* parameter, but the Zig
implementation only accepted a *Text parameter. This caused the
surface pointer to be interpreted as the text pointer, so the
actual text allocation was never freed.
2026-03-31 09:46:35 -07:00
Elias Andualem
1d0a247c20 sort map alphabetically 2026-03-31 19:34:52 +08:00
Elias Andualem
30c9dec76b add all C struct layout metadata for WASM 2026-03-31 19:28:46 +08:00
Mitchell Hashimoto
50f3b1d60d libghostty: export function table and make it growable for wasm (#12003)
Replaces #11958

This exports the function table and makes it growable so that the
effects API can be used. It's still very not ergonomic to use the
effects API so I'm going to work on that next, but this at least makes
it _possible_. Zig 0.15.x is missing the ability to pass
`--growable-table` to the linker so we use binary patching to add it
(yay!) lol.
2026-03-30 15:29:29 -07:00
Barut
a83a82b3f8 build: normalize input archives before Darwin libtool merge
Apple's recent libtool can warn about misaligned 64-bit archive members
and silently drop them when merging static libraries. In Ghostty this
showed up in the Darwin libtool step that builds libghostty-fat.a.

Normalize each input archive by copying it and running ranlib on the
copy
before handing it to libtool. That rewrites the archive into a layout
Apple's linker tools accept without flattening members through the
filesystem or changing Ghostty's archive format.
2026-03-30 16:59:07 -04:00
Mitchell Hashimoto
01a8ea7212 build: binary patching with Zig 2026-03-30 12:06:41 -07:00
Mitchell Hashimoto
6c085e5442 build: binary patch to add growable tables 2026-03-30 11:41:24 -07:00
Mitchell Hashimoto
624b4884c3 Add build_table 2026-03-30 11:34:09 -07:00
Mitchell Hashimoto
bd7415f4b7 terminal: clean up some types tests 2026-03-30 10:21:08 -07:00
Mitchell Hashimoto
0c38e8be60 vt: simplify ghostty_type_json to return null-terminated string
The function previously took a size_t* out-parameter for the string
length. Since the JSON blob is now null-terminated, the len parameter
is unnecessary. Remove it from the Zig implementation, C header, and
the WASM example consumer which no longer needs to allocate and free
a usize just to read the length.
2026-03-30 10:16:19 -07:00
Mitchell Hashimoto
2e827cc39d vt: add ghostty_type_json for struct layout metadata
Add a new C API function that returns a comptime-generated JSON string
describing the size, alignment, and field layout of every C API extern
struct. This lets FFI consumers (particularly WASM) construct structs
by byte offset without hardcoding platform-specific layout.

The JSON is built at comptime using std.json.Stringify via a
StructInfo type that holds per-struct metadata and implements
jsonStringify. A StaticStringMap keyed by C struct name provides
lookup by name as well as iteration for the JSON serialization.

The function is declared in types.h alongside the other common types
and exported as ghostty_type_json.
2026-03-30 10:16:19 -07:00
Mitchell Hashimoto
f66cf179cd gtk: only trigger resize callbacks and overlay when size actually changes (#11972)
Fixes #11970

Also fixes problem that resize overlay would intercept mouse activity
while active.
2026-03-30 08:45:50 -07:00
Jon Parise
840ab46009 cli: also recognize $GHOSTTY_PAGER
When defined, GHOSTTY_PAGER takes precedence over PAGER. If either of
those variables is set to an empty value, paging is disabled.
2026-03-30 10:53:53 -04:00
Jon Parise
11d45cd43c cli: add pager support for +show-config 2026-03-30 10:48:07 -04:00
Jon Parise
62f8a1cbcf cli: use a caller-provided write buffer
This follows Zig's conventions more closely, where the caller owns the
write buffer.
2026-03-30 10:48:07 -04:00
Jon Parise
4a0cca1c5b cli: add pager support to +explain-config
Add a new Pager type that wraps output to an external pager program when
stdout is a TTY, following the same conventions as git. The pager
command is resolved from $PAGER, falling back to `less`. An empty $PAGER
disables paging. If the pager fails to spawn, we fall back to stdout.

Previously, +explain-config wrote directly to stdout with no paging,
which meant long help text would scroll by. Now output is automatically
piped through the user's preferred pager when running interactively. A
--no-pager flag is available to disable this.
2026-03-30 10:48:07 -04:00
Jeffrey C. Ollie
af36959942 gtk: only trigger resize callbacks and overlay when size actually changes
Fixes #11970

Also fixes problem that resize overlay would intercept mouse activity
while active.
2026-03-29 23:38:34 -05:00
Mitchell Hashimoto
d784600fd6 terminal: update page_serial_min in erasePage
Fixes #11957

erasePage now updates page_serial_min when the first page is erased,
and asserts that only front or back pages are erased since
page_serial_min cannot represent serial gaps from middle erasure.

To enforce this invariant at the API level, PageList.eraseRows is
now private. Two public wrappers replace it: eraseHistory always
starts from the beginning of history, and eraseActive takes a y
coordinate (with bounds assertion) and always starts from the top
of the active area. This makes middle-page erasure impossible by
construction.
2026-03-29 15:10:12 -07:00
Elias Andualem
420de124f0 fix: ensure memory is zeroed in runtime safety modes for wasm/freestanding 2026-03-29 17:28:18 +08:00
Mitchell Hashimoto
0f6e733f8c build: use VERSION file if present, expose via libghostty (#11932)
If a `VERSION` file is present from our build root, prefer that as our
version source of truth over `build.zig.zon`. This file is automatically
created in source tarballs and will allow us to cut pre-release tarballs
of libghostty in particular (but affects all) that has a more specific
version than what can be in build.zig.zon.

This also adds the APIs necessary to extract this via the C API.

I started prepping for a separate libghostty version but not sure if
I'll wire that up in this PR yet or not...
2026-03-28 18:29:34 -07:00
Jeffrey C. Ollie
4903e2821d gtk: disable kinetic scrolling for trackpads until 4.20.1 (#11793)
Until gtk 4.20.1 trackpads have kinetic scrolling behavior regardless of
`Gtk.ScrolledWindow.kinetic_scrolling`. As a workaround, set
EventControllerScroll.kinetic to false on all controllers.

`observeControllers()` has this warning:
> Calling this function will enable extra internal bookkeeping to track
controllers and emit signals on the returned listmodel. It may slow down
operations a lot.
> Applications should try hard to avoid calling this function because of
the slowdowns.

but judging from the
[source](5301a91f1c/gtk/gtkwidget.c (L12375-L12383))
this is a one time penalty since we free the result immediately
afterwards.

Fixes https://github.com/ghostty-org/ghostty/discussions/11460.

### AI usage
Zed + Opus 4.5 generated the first pass, but it missed freeing the
result of `observeControllers()` and conveniently binding
`scrolled_window` to the blueprint. Figuring out what was going on also
took a lot of [human
debugging](https://github.com/ghostty-org/ghostty/discussions/11460#discussioncomment-16245664).
2026-03-28 19:08:15 -05:00
Michael Stevens
c0a124f3ca gtk: disable kinetic scrolling for trackpads until 4.20.1
Until gtk 4.20.1 trackpads have kinetic scrolling behavior regardless
of `Gtk.ScrolledWindow.kinetic_scrolling`. As a workaround, set
EventControllerScroll.kinetic to false on all controllers.

`observeControllers()` has this warning:
> Calling this function will enable extra internal bookkeeping to track controllers and emit signals on the returned listmodel. It may slow down operations a lot.
> Applications should try hard to avoid calling this function because of the slowdowns.

but judging from the [source](5301a91f1c/gtk/gtkwidget.c (L12375-L12383))
this is a one time penalty since we free the result immediately afterwards.

Fixes https://github.com/ghostty-org/ghostty/discussions/11460
2026-03-28 17:36:17 -04:00
Mitchell Hashimoto
8fa50f84d7 cli: dupe argument strings to retain their memory (#11931)
The argument iterator's .next() method returns a transient slice of the
command line buffer so we need to make our own copies of these values to
avoid referencing stale memory.
2026-03-28 09:26:28 -07:00
Mitchell Hashimoto
8813261341 libghostty: expose version information via build options and C API
Add version (std.SemanticVersion) to the terminal build options so that
the terminal module has access to the application version at comptime.
The add() function breaks it out into version_string, version_major,
version_minor, version_patch, and version_build terminal options.

On the C API side, five new GhosttyBuildInfo variants expose these
through ghostty_build_info(). String values use GhosttyString; numeric
values use size_t. When no build metadata is present, version_build
returns a zero-length string.

The c-vt-build-info example is updated to query and print all version
fields.
2026-03-28 09:17:52 -07:00
Jon Parise
2b1ec5db6d cli: dupe argument strings to retain their memory
The argument iterator's .next() method returns a transient slice of the
command line buffer so we need to make our own copies of these values to
avoid referencing stale memory.
2026-03-28 12:14:28 -04:00
Mitchell Hashimoto
608bc7d24d cli: +edit-config works properly when editor command contains arguments (#11898)
If `$EDITOR` or `$VISUAL` contained arguments, not just the path to an
editor (e.g. `zed --new`) `+edit-config` would fail because we were
treating the whole command as a path. Instead, wrap the command with
`/bin/sh -c <command>` so that the shell can separate the path from the
arguments.

Fixes #11897
2026-03-28 08:57:30 -07:00
Mitchell Hashimoto
e20b50652a fix: replace hardcoded locale.h constants with build-system TranslateC (#11920)
Replace hardcoded locale.h constants and extern function declarations
with build-system TranslateC, following the same pattern as pty.c.

This fixes LC_ALL being hardcoded to 6 (the musl/glibc implementation
value), which is implementation-defined and differs on Windows MSVC
(where LC_ALL is 0), causing `setlocale()` to crash with an invalid
parameter error.

## Changes

- Added `src/os/locale.c` — includes `locale.h` for TranslateC
- Added TranslateC step in `src/build/SharedDeps.zig` (same pattern as
pty.c)
- Replaced hardcoded constants and extern declarations in
`src/os/locale.zig` with `@import("locale-c")`

## AI disclosure

Claude Code was used to assist with debugging and identifying this
issue.
2026-03-28 08:56:40 -07:00
Jeffrey C. Ollie
60c7e767a8 benchmark: disable test on windows
We don't appear to have a time source with enough resolution to get a
non-zero duration on the benchmark test so it fails.
2026-03-28 10:20:51 -05:00
i999rri
f0badd34d3 fix: replace hardcoded locale.h constants with build-system TranslateC
Replace hardcoded locale.h constants and extern function declarations
with build-system TranslateC, following the same pattern as pty.c.

This fixes LC_ALL being hardcoded to 6 (musl/glibc value), which is
implementation-defined and differs on Windows MSVC (where LC_ALL is 0),
causing setlocale() to crash with an invalid parameter error.
2026-03-28 22:59:10 +09:00
Jeffrey C. Ollie
cb3c20befe cli: escape path in +edit-config 2026-03-27 12:24:26 -05:00
Jeffrey C. Ollie
6491363157 cli: +edit-config works properly when editor command contains arguments
If `$EDITOR` or `$VISUAL` contained arguments, not just the path to
an editor (e.g. `zed --new`) `+edit-config` would fail because we were
treating the whole command as a path. Instead, wrap the command with
`/bin/sh -c <command>` so that the shell can separate the path from
the arguments.

Fixes #11897
2026-03-27 10:08:20 -05:00
Mitchell Hashimoto
b8b0896324 ci: add full zig test suite for Windows (#11839)
## Summary

This PR effectively enables testing for all the Windows related stuff
that is coming soon.

> [!IMPORTANT]
>This PR builds on top of #11782 which fixes the last (as we speak) bug
that we have in the Windows pipeline. So it would be great to review
that PR first and then work on this one. Then we'll have the real
windows testing, basically achieving parity, infrastructurally, with the
other platforms.

What it does:

- Add a `test-windows` job to the CI workflow that runs the full test
suite (`zig build -Dapp-runtime=none test`) on Windows
- Add `test-windows` to the `required` checks list so it gates merges

## Context
The existing `build-libghostty-vt-windows` job only runs `zig build
test-lib-vt` (the VT library subset).
I realized that in c5092b09d we removed the TODO comment in that job:
"Work towards passing the full test suite on Windows."
But effectively we weren't running tests in CI yet! 

The full test suite now passes on Windows (51/51 steps, 2654 tests, 23
skipped). This job mirrors what the other platforms do — Linux runs `zig
build -Dapp-runtime=none test` via Nix, macOS runs `zig build test` via
Nix. Windows runs the same command directly via `setup-zig` since
there's no Nix on Windows.

## How
The new job follows the same pattern as the other Windows CI jobs:
- `runs-on: windows-2025` (same as `build-libghostty-vt-windows` and
`build-examples-cmake-windows`)
- `timeout-minutes: 45` (same as other Windows jobs)
- `needs: skip` so it runs early in parallel (same as `test-macos` and
the main `test` job), not gated behind other jobs
- Uses `mlugg/setup-zig` (same pinned version as other Windows jobs)
- Runs `zig build -Dapp-runtime=none test`

## Dependencies
This job will only pass once the following PRs are merged:
- PR #11782 -> backslash path handling in CommaSplitter/Theme
- PR #11807 -> freetype compilation fix
- PR #11810 -> ssize_t typedef for MSVC
- PR #11812 -> linkLibCpp skip + freetype enum signedness
- Others I have missed probably but they are merged already.

## Test plan
- The workflow YAML is valid (standard GitHub Actions syntax, matches
existing job patterns)
- I will be ready to issue fix PRs if any issue related to this arises.
I cannot reliably test GH actions locally unfortunately.
- Once dependencies land, the job should produce: 51/51 steps, ~2654
tests pass, 23 skipped
- No impact on existing Linux/macOS CI jobs

## What I Learnt
- GitHub Actions Windows runners don't have Nix, so Windows jobs use
`setup-zig` directly while Linux/macOS jobs use `nix develop -c zig
build ...`. The Nix wrapper ensures the exact same environment as the
flake, but on Windows we get that consistency from the `setup-zig`
action which reads the version from `build.zig.zon`.
- The `needs: skip` pattern allows a job to run in parallel with the
main test job rather than waiting for it. The main `test` job is the
gatekeeper for most build jobs (`needs: test`), but platform-specific
test jobs like `test-macos` run in parallel since they're independent.
- The `required` job aggregates all needed jobs and uses a grep-based
check to determine overall pass/fail, so adding a new job there means it
becomes a merge blocker.
2026-03-27 06:28:34 -07:00
Alessandro De Blasis
650b9d470a font: handle CRLF line endings in octants.txt parsing
Trim trailing \r when splitting octants.txt by \n at comptime. On
Windows, git may convert LF to CRLF on checkout, leaving \r at the
end of each line. Without trimming, the parser tries to use \r as
a struct field name in @field(), causing a compile error.

Follows the same pattern used in x11_color.zig for rgb.txt parsing.
2026-03-27 06:11:20 -07:00
Alessandro De Blasis
ca08ab8619 windows: simplify DLL init test and improve README 2026-03-27 06:04:09 -07:00
Alessandro De Blasis
5d92222621 windows: address review feedback on DLL CRT init PR
Use b.allocator instead of b.graph.arena for SDK detection and
path formatting -- b.allocator is the public API, b.graph.arena
is an internal field.

Move test_dll_init.c from windows/Ghostty.Tests/ to test/windows/
with a README. Test infrastructure belongs under test/, not the
Windows app directory.
2026-03-27 06:04:09 -07:00
Alessandro De Blasis
656700d803 windows: remove unrelated changes from DLL CRT fix branch
Revert .gitattributes, CI test-windows job, and CRLF octants.txt
fix back to main. These belong in their own branches/PRs.
2026-03-27 06:04:09 -07:00
Alessandro De Blasis
6afc174a4f windows: remove .NET test infrastructure and CRT probe function
The C# test suite and ghostty_crt_workaround_active() probe were
unnecessary overhead. The DllMain workaround is harmless to keep
(CRT init is ref-counted) and comments document when to remove it.
test_dll_init.c remains as a standalone C reproducer.
2026-03-27 06:04:09 -07:00
Alessandro De Blasis
f764b16465 windows: add DLL init regression tests and probe
C# test suite and C reproducer validating DLL initialization.

The probe test (DllMainWorkaround_IsStillActive) checks that the CRT
workaround is compiled in via ghostty_crt_workaround_active(). When
Zig fixes MSVC DLL CRT init, removing the DllMain will make this test
fail with instructions on how to verify the fix and clean up.

ghostty_init is tested via the C reproducer (test_dll_init.c) rather
than C# because the global state teardown crashes the test host on
DLL unload. The C reproducer exits without FreeLibrary.
2026-03-27 06:04:09 -07:00
Alessandro De Blasis
a0785710bb windows: initialize MSVC C runtime in DLL mode
Zig's _DllMainCRTStartup does not initialize the MSVC C runtime when
building a shared library targeting MSVC ABI. This means any C library
function that depends on CRT internal state (setlocale, glslang,
oniguruma) crashes with null pointer dereferences because the heap,
locale, and C++ runtime are never set up.

Declare a DllMain that calls __vcrt_initialize and __acrt_initialize
on DLL_PROCESS_ATTACH. Zig's start.zig checks @hasDecl(root, "DllMain")
and calls it during _DllMainCRTStartup. Uses @extern to get function
pointers without pulling in CRT objects that would conflict with Zig's
own _DllMainCRTStartup symbol.

Only compiles on Windows MSVC (comptime guard). On other platforms and
ABIs, DllMain is void and has no effect.
2026-03-27 06:04:09 -07:00
Alessandro De Blasis
335d7f01db build: fix ghostty.dll linking on Windows MSVC
linkLibC() provides msvcrt.lib for DLL targets but doesn't include the
companion CRT bootstrap libraries. The DLL startup code in msvcrt.lib
calls __vcrt_initialize and __acrt_initialize, which live in the static
CRT libraries (libvcruntime.lib, libucrt.lib).

Detect the Windows 10 SDK installation via std.zig.WindowsSdk to add
the UCRT library path, which Zig's default search paths don't include
(they add um\x64 but not ucrt\x64).

This is a workaround for a Zig gap (partially addressed in closed
issues 5748, 5842 on ziglang/zig). Only affects initShared (DLL),
not initStatic.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-27 06:04:09 -07:00
Alessandro De Blasis
29cf0078a7 font: handle CRLF line endings in octants.txt parsing
Trim trailing \r when splitting octants.txt by \n at comptime. On
Windows, git may convert LF to CRLF on checkout, leaving \r at the
end of each line. Without trimming, the parser tries to use \r as
a struct field name in @field(), causing a compile error.

Follows the same pattern used in x11_color.zig for rgb.txt parsing.
2026-03-27 06:04:09 -07:00
Mitchell Hashimoto
7801e97127 terminal: redo trailing state capture in OSC parser
Trailing state capture now is encapsulated in a struct `Capture` and all
parsers access the data via `p.capture.trailing()` rather than directly
from the writer.

This is primarily to prep for the OSC parser to be able to capture the
entire sequence (not just the trailing part) so we can setup libghostty
for fallback handlers so libghostty implementers can have custom OSC
behaviors.

But, it has the benefit of making our OSC parser much cleaner too.
2026-03-26 13:57:42 -07:00
Mitchell Hashimoto
11574c35a2 libghostty: expose paste encode to C API
Add ghostty_paste_encode() which encodes paste data for writing to
the terminal pty. It strips unsafe control bytes, wraps in bracketed
paste sequences when requested, and replaces newlines with carriage
returns for unbracketed mode. The input buffer is modified in place
and the encoded result is written to a caller-provided output buffer,
following the same buffer/out_written pattern as the other encode
functions like ghostty_size_report_encode.

Update the c-vt-paste example with an encode_example() demonstrating
the new function and add corresponding @snippet references in the
header documentation.
2026-03-26 11:28:23 -07:00