Commit Graph

15463 Commits

Author SHA1 Message Date
Mitchell Hashimoto
01401ef675 build: fix Windows static lib linking with MSVC
Three issues when linking the static library with the MSVC linker:

Use the LLVM backend on Windows to produce valid COFF objects.
The self-hosted backend generates compiler_rt objects with invalid
COMDAT sections that the MSVC linker rejects (LNK1143).

Disable bundling ubsan_rt on Windows. Zig's ubsan runtime emits
/exclude-symbols linker directives that MSVC does not understand
(LNK4229).

Add ntdll and kernel32 as transitive link dependencies for the
static library on Windows. The Zig standard library uses NT API
functions (NtClose, NtCreateSection, etc.) that consumers must
link.
2026-03-23 11:31:41 -07:00
Mitchell Hashimoto
2c89bef860 build: skip bundled compiler_rt and ubsan_rt in Windows static lib
Zig's compiler_rt produces COFF objects with invalid COMDAT
sections that the MSVC linker rejects (LNK1143), and its ubsan_rt
emits /exclude-symbols directives that MSVC does not understand
(LNK4229). Skip bundling both in the static library on Windows
since the MSVC CRT provides the needed builtins (memcpy, memset,
etc.). The shared library continues to bundle compiler_rt as it
needs to be self-contained.
2026-03-23 11:20:20 -07:00
Mitchell Hashimoto
69f82ec751 build: disable bundled ubsan runtime on Windows
Zig's ubsan runtime emits /exclude-symbols linker directives that
are incompatible with the MSVC linker, causing LNK4229 warnings and
LNK1143 errors. Disable bundling ubsan_rt on Windows while keeping
compiler_rt which provides essential symbols like memcpy, memset,
memmove, and ___chkstk_ms.

The previous check used target.result.abi == .msvc which never
matched because Zig defaults to the gnu ABI on Windows.
2026-03-23 11:12:19 -07:00
Mitchell Hashimoto
1ce057f053 build: disable ubsan and bundled runtimes for MSVC targets
Zig's ubsan instrumentation emits ELF-style /exclude-symbols linker
directives into the compiled object files, causing LNK4229 warnings
with the MSVC linker. The bundled compiler_rt also produces COMDAT
sections that are incompatible with MSVC, causing fatal LNK1143.

Disable sanitize_c entirely on the root module for MSVC targets and
skip bundling both compiler_rt and ubsan_rt since MSVC provides its
own runtime.
2026-03-23 11:04:28 -07:00
Mitchell Hashimoto
31285e1ac3 build: disable bundled compiler_rt and ubsan_rt for MSVC targets
Zig's bundled compiler_rt and ubsan_rt produce object files with
ELF-style linker directives (/exclude-symbols) and COMDAT sections
that are incompatible with the MSVC linker, causing LNK1143 and
LNK4229 errors when linking the static library.

MSVC provides its own compiler runtime so bundling Zig's versions
is unnecessary. Skip bundling both runtimes when the target ABI is
MSVC.
2026-03-23 10:42:10 -07:00
Mitchell Hashimoto
2afadfc104 build: fix Windows cmake example failures
The cmake examples were failing at runtime on Windows CI for two
reasons.

The static library was installed as "libghostty-vt.a" on all
platforms, but on Windows the DLL import library is also placed in
zig-out/lib/ as "ghostty-vt.lib". The CMakeLists.txt expected the
platform-native name "ghostty-vt.lib" for the static lib, so it
picked up the tiny DLL import lib instead, silently producing a
dynamically-linked executable. That executable then failed at
runtime because the DLL was not on PATH.

Fix this by installing the static library as "ghostty-vt-static.lib"
on Windows to avoid the name collision, and updating CMakeLists.txt
to match. For the shared (DLL) example, add zig-out/bin to PATH in
the CI run step so the DLL can be found at runtime.
2026-03-23 10:32:22 -07:00
Mitchell Hashimoto
6ccc01a852 revert the build-windows 2026-03-23 10:31:31 -07:00
Mitchell Hashimoto
0fdddd5bc2 Revert "build: fix Windows build failures in helpgen and framegen"
This reverts commit 704511465b.
2026-03-23 10:31:11 -07:00
Mitchell Hashimoto
48cf3f36cd ci: run Windows CMake examples after building
Add a "Run Example" step to the build-examples-cmake-windows job
so that each CMake example is executed after it is built, verifying
the resulting binaries actually work. The executable name is derived
from the matrix directory name by replacing hyphens with underscores,
matching the project convention.
2026-03-23 10:31:11 -07:00
Mitchell Hashimoto
f4998c6abb build: fix Windows build failures in helpgen and framegen
Use writerStreaming() instead of writer() for stdout in helpgen and
main_build_data. The positional writer calls setEndPos/ftruncate in
end(), which fails on Windows when stdout is redirected via
captureStdOut() because ftruncate maps INVALID_PARAMETER to
FileTooBig. Streaming mode skips truncation entirely since stdout
is inherently a sequential stream.

Replace scandir with opendir/readdir plus qsort in framegen since
scandir is a POSIX extension not available on Windows.
2026-03-23 10:31:11 -07:00
Mitchell Hashimoto
5a46e61bee cmake: fix Windows build support
On Windows, shared libraries (DLLs) require an import library (.lib)
for linking, and the DLL itself is placed in bin/ rather than lib/ by
the Zig build. The CMake wrapper was missing IMPORTED_IMPLIB on the
shared imported target, causing link failures, and assumed the shared
library was always in lib/.

Add GHOSTTY_VT_IMPLIB for the import library name, set IMPORTED_IMPLIB
on the ghostty-vt target, and fix the shared library path to use bin/
on Windows. Install the DLL and PDB to bin/ and the import library to
lib/ following standard Windows conventions. Apply the same fixes to
ghostty-vt-config.cmake.in for the find_package path.
2026-03-23 10:31:11 -07:00
Mitchell Hashimoto
fa10237fb0 build: fix windows build to properly run tests and build of libghostty-vt (#11781)
Our Windows build has been broken for a _long_ time. It hasn't actually
worked and our CI was falsely passing when it was actually failing to
build/test. This PR fixes that and fixes the issues it found so
`libghostty-vt` can build and pass tests.

**This is only for libghostty!** I'd still like to expand our _test_
coverage to all of Ghostty for Windows but libghostty is more important
for that platform in the short term and it's an incremental piece of
work.

A couple windows compatibility issues fixed:

- `terminal.Page` uses `VirtualAlloc` on Windows (thanks @deblasis)
- Our rgb.txt loading was not resilient to CRLF endings
2026-03-23 10:29:45 -07:00
Mitchell Hashimoto
e95fdd2f21 terminal: handle CRLF line endings in rgb.txt parsing
The X11 color map parser in x11_color.zig uses @embedFile to load
rgb.txt at comptime, then splits on \n. On Windows, git may check
out rgb.txt with CRLF line endings, leaving a trailing \r on each
line. This caused color names to be stored as e.g. "white\r" instead
of "white", so all X11 color lookups failed at runtime.

Strip trailing \r from each line before parsing. Also mark rgb.txt
as -text in .gitattributes to prevent line ending conversion in
future checkouts.
2026-03-23 10:15:16 -07:00
Mitchell Hashimoto
d568ce9cc8 terminal: support VirtualAlloc for page allocation on windows
Extract the platform-specific page backing memory allocation into
AllocPosix and AllocWindows structs behind a PageAlloc comptime
switch. Previously, POSIX mmap calls were inlined at each call
site. This adds a Windows VirtualAlloc implementation and routes
all allocation through PageAlloc.alloc/free, making the backing
memory strategy consistent and easier to extend.
2026-03-23 10:04:43 -07:00
Mitchell Hashimoto
aa969df679 ci: clean up Windows build job
Rename build-windows to build-libghostty-vt-windows to reflect that
it only builds and tests libghostty-vt for now, and move it next to
the other build-libghostty-vt jobs.

Replace the manual PowerShell zig download/install with mlugg/setup-zig,
which auto-detects the version from build.zig.zon and handles caching.
Upgrade the runner from windows-2022 to windows-2025. Remove the
generated-script-to-swallow-errors pattern in favor of direct zig
build commands.
2026-03-23 09:39:00 -07:00
Mitchell Hashimoto
206f9894f7 Fix zig build test-lib-vt (#11778)
- Our `checkGhosttyH` calls need to be guarded on building Ghostty app
which has it
- Move FileFormatter to its own file to avoid poisoning test refs with
Config.zig which pulls in the world
- Move WindowPaddingBalance to renderer to avoid pulling in Config.zig
- Add a `zig build test-lib-vt` CI job
2026-03-23 09:38:40 -07:00
Mitchell Hashimoto
3c8d0a9c25 vt: fix test failures in render and key_encode
The colors_get function used structSizedFieldFits to guard the
palette copy, which required the entire palette array to fit in the
provided size. This prevented partial palette writes when the caller
passed a truncated sized struct, since the guard failed even though
the inner code already handled partial copies correctly. Remove the
outer guard so the existing partial-copy logic applies.

The setopt_from_terminal test expected alt_esc_prefix to be false on
a fresh terminal, but the mode definition in modes.zig sets its
default to true. Update the test expectation to match.
2026-03-23 09:23:32 -07:00
Mitchell Hashimoto
f92bb74196 ci: add test-lib-vt job
Add a new CI job that runs `zig build test-lib-vt` to test the
lib-vt build step. The job mirrors the existing test job structure
with the same nix/cachix setup and skip conditions. It is also
added to the required checks list.
2026-03-23 09:21:37 -07:00
Mitchell Hashimoto
58283528c7 vt: handle invalid enum before pointer cast in getters
The inline else switch in each C API getter expands the .invalid
case, which has OutType void. When called with .invalid and a null
out pointer, the @ptrCast(@alignCast(out)) panics before getTyped
can return early.

Handle .invalid explicitly in the outer switch of every getter to
short-circuit before the pointer cast. This affects build_info,
cell, row, terminal, osc, and render (three getters).
2026-03-23 09:19:52 -07:00
Mitchell Hashimoto
409f05c927 typos 2026-03-23 09:17:34 -07:00
Mitchell Hashimoto
51f878417f reenable tests 2026-03-23 09:15:33 -07:00
Mitchell Hashimoto
f60587ffcc renderer/size: move PaddingBalance enum out of Config
Previously WindowPaddingBalance was defined inside Config.zig, which
meant tests for renderer sizing had to pull in the full config
dependency. Move the enum into renderer/size.zig as PaddingBalance
and re-export it from Config so the public API is unchanged. This
lets size.zig tests run without depending on Config.
2026-03-23 09:14:46 -07:00
Mitchell Hashimoto
7253668ec2 config: move file formatter to dedicated file to prevent import bloat 2026-03-23 09:11:23 -07:00
Mitchell Hashimoto
04b5dc7332 terminal: guard ghostty.h checks on building the app 2026-03-23 09:03:21 -07:00
Mitchell Hashimoto
9b3f7a9287 vt: also build static libghostty-vt for wasm (#11757)
A static libghostty-vt is also useful for wasm targets, as that allows
linking with an application into a larger wasm module.

See
https://github.com/ghostty-org/ghostty/pull/11729#issuecomment-4106589379
2026-03-23 08:52:56 -07:00
Bastian Müller
d67f65e38c also build static libghostty-vt for wasm 2026-03-23 08:36:04 -07:00
Jeffrey C. Ollie
374ed27214 gtk: Open URIs with portals (#11754)
This is a continuation of the solid work done by @jcollie in PR #7864. I
checked with him if I could take over to continue the implementation.

His changes of last year have been adapted to be compatible with the
current GTK implementation. Aside from just "making it work", I also
dived into the portals and OpenURI implementation and made some
improvements there.

Notable improvements were:
- Improved lifecycle management of glib resources in the OpenURI
implementation
- More forgiving error handling in OpenURI implementation by adding more
fallbacks
- Fixed some memory leaks
- Less memory allocations in Portals implementation
- Added tests for building the Portals request path

Fixes #5991
2026-03-23 09:44:49 -05:00
ghostty-vouch[bot]
f0d59c22b2 Update VOUCHED list (#11775)
Triggered by
[comment](https://github.com/ghostty-org/ghostty/issues/11768#issuecomment-4111147332)
from @jcollie.

Vouch: @lynicis

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2026-03-23 14:41:18 +00:00
ghostty-vouch[bot]
f6cf978b32 Update VOUCHED list (#11773)
Triggered by
[comment](https://github.com/ghostty-org/ghostty/issues/11771#issuecomment-4111016256)
from @jcollie.

Vouch: @deblasis

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2026-03-23 14:24:45 +00:00
Timon de Groot
8bc75907b5 gtk: Fix casing for openUri 2026-03-23 07:29:36 +01:00
ghostty-vouch[bot]
1d54a94ced Update VOUCHED list (#11755)
Triggered by
[comment](https://github.com/ghostty-org/ghostty/issues/11754#issuecomment-4106929553)
from @mitchellh.

Vouch: @tdgroot

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2026-03-22 20:28:50 +00:00
Timon de Groot
919e586c51 gtk/portal: Improve OpenURI lifecycle 2026-03-22 21:10:46 +01:00
Timon de Groot
37d297c03c gtk/portal: General improvements
- Token is formatted without allocation
- Reusable function for formatToken
- Tests in portal.zig are actuall included now
2026-03-22 21:09:38 +01:00
Timon de Groot
855a6b01fc gtk: Open urls with openuri portal 2026-03-22 18:17:09 +01:00
Mitchell Hashimoto
7d816f8e81 Update README (#11748)
The README hasn't been updated in years basically! 

This updates the README to make libghostty a first class citizen of the
project and to update our roadmap and goals for the project to more
accurately reflect our current state and future plans.

I notably updated our roadmap to be more accurate to our state, e.g.
we're stable now. I removed Windows because it's not a short term focus
and I think libghostty is more important and enables that ecosystem a
lot more (libghostty itself being already compatible with Windows). I
also expanded on "fancy features" and clarified its to make
Ghostty-specific sequences.
2026-03-22 07:59:36 -07:00
Mitchell Hashimoto
1f2a3b8a83 update README
The README hasn't been updated in years basically! 

This updates the README to make libghostty a first class citizen of the
project and to update our roadmap and goals for the project to more
accurately reflect our current state and future plans.
2026-03-22 07:58:53 -07:00
Mitchell Hashimoto
ecc55b94c8 libghostty: add resolved bg_color and fg_color to cells API (#11735)
Fixes #11705

Add bg_color and fg_color options to GhosttyRenderStateRowCellsData that
resolve the final RGB color for a cell, flattening the multiple possible
sources. For background, this handles content-tag bg_color_rgb,
content-tag bg_color_palette (looked up in the palette), and the style
bg_color. For foreground, this resolves palette indices through the
palette; bold color handling is not applied and is left to the caller.

Both return GHOSTTY_INVALID_VALUE when no explicit color is set, in
which case the caller should fall back to whatever default color it
wants (e.g. the terminal background/foreground).
2026-03-22 06:44:35 -07:00
ghostty-vouch[bot]
8a788a350e Update VOUCHED list (#11741)
Triggered by [discussion
comment](https://github.com/ghostty-org/ghostty/discussions/11737#discussioncomment-16252675)
from @pluiedev.

Denounce: @kody-w

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2026-03-22 08:20:46 +00:00
Mitchell Hashimoto
ad5e9679c8 terminal: default render state foreground to white (#11736)
Fixes #11704

The RenderState empty initializer set both background and foreground to
the default RGB value of black (0, 0, 0), making text unreadable when a
caller has not explicitly configured terminal colors via DynamicRGB.
This is the common case for libghostty consumers.

Default the foreground to white so that the initial render state
provides readable white-on-black text out of the box.

Long term we also need to expose setting the default colors for a
Terminal instance but this is a workable fix in the mean time.
2026-03-21 20:30:32 -07:00
Mitchell Hashimoto
8bd3a493be libghostty: add resolved bg_color and fg_color to cells API
Fixes #11705

Add bg_color and fg_color options to GhosttyRenderStateRowCellsData
that resolve the final RGB color for a cell, flattening the multiple
possible sources. For background, this handles content-tag bg_color_rgb,
content-tag bg_color_palette (looked up in the palette), and the
style bg_color. For foreground, this resolves palette indices through
the palette; bold color handling is not applied and is left to the
caller.

Both return GHOSTTY_INVALID_VALUE when no explicit color is set, in
which case the caller should fall back to whatever default color it
wants (e.g. the terminal background/foreground).
2026-03-21 20:30:01 -07:00
Mitchell Hashimoto
32c97a019f terminal: default render state foreground to white
Fixes #11704

The RenderState empty initializer set both background and foreground
to the default RGB value of black (0, 0, 0), making text unreadable
when a caller has not explicitly configured terminal colors via
DynamicRGB. This is the common case for libghostty consumers.

Default the foreground to white so that the initial render state
provides readable white-on-black text out of the box.

Long term we also need to expose setting the default colors for a
Terminal instance but this is a workable fix in the mean time.
2026-03-21 20:24:02 -07:00
Mitchell Hashimoto
0c2bafcc2a libghostty: expose mouse_tracking terminal data option (#11734)
Fixes #11706

Add a new GHOSTTY_TERMINAL_DATA_MOUSE_TRACKING option to the
ghostty_terminal_get API. This returns true if any mouse tracking mode
is active (X10, normal, button, or any-event), replacing the need for
consumers to loop over four separate mode queries.
2026-03-21 20:19:22 -07:00
Mitchell Hashimoto
47bfde3286 libghostty: expose mouse_tracking terminal data option
#11706

Add a new GHOSTTY_TERMINAL_DATA_MOUSE_TRACKING option to the
ghostty_terminal_get API. This returns true if any mouse tracking
mode is active (X10, normal, button, or any-event), replacing the
need for consumers to loop over four separate mode queries.
2026-03-21 20:09:39 -07:00
Mitchell Hashimoto
1775c312ae libghostty: add static library support (#11732)
Multiple changes:

* `zig build -Demit-lib-vt` now produces both shared and static
libraries by default
* Ghosty as a zig build dependency exports the static lib as
`dep.artifact("ghostty-vt-static")`
* CMake exports the static lib as `ghostty-vt-static`

Note that the static library is _not fat_. **If you enable SIMD you have
dependencies** and you need to manually link those: libc++, simdutf, and
highway. The `c-cmake-static` example disables SIMD.
2026-03-21 15:23:00 -07:00
Mitchell Hashimoto
5fd36ea69e build: enable PIC for static libghostty-vt
The static library was built without position-independent code,
which caused linker errors when consumers tried to link it into
PIE executables (the default on most Linux distributions). The
linker would fail with "relocation R_X86_64_32 against symbol
cannot be used when making a PIE object."

Enable PIC on the static library root module so it can be linked
into both PIE and non-PIE executables.
2026-03-21 15:15:17 -07:00
Mitchell Hashimoto
555bf7e922 build: add cmake static library support
Expose both shared and static libraries as separate CMake imported
targets (ghostty-vt and ghostty-vt-static) rather than toggling
between them with BUILD_SHARED_LIBS. The zig build already produces
both in a single invocation, so both are always available.

The find_package config template is updated to export both targets
as ghostty-vt::ghostty-vt and ghostty-vt::ghostty-vt-static.

Add a c-vt-cmake-static example that demonstrates linking the static
library via FetchContent with -Dsimd=false to avoid C++ runtime
dependencies.
2026-03-21 15:08:24 -07:00
Mitchell Hashimoto
8d6be5a3dd build: add static library target for libghostty-vt
Refactor GhosttyLibVt to support both shared and static library
builds via a shared initLib helper that accepts a LinkMode. The
shared and static entry points (initShared, initStatic) delegate
to this common path.

For static builds, compiler_rt and ubsan_rt are bundled to avoid
undefined symbol errors. Debug symbols (dsymutil) are skipped for
static libs since they are not linked. The install artifact uses
a "-static" suffix internally but installs as "libghostty-vt.a"
via a new installLib method. Wasm is excluded from static builds
since it has no meaningful static vs shared distinction.
2026-03-21 15:01:53 -07:00
ghostty-vouch[bot]
1438a2fe4b Update VOUCHED list (#11731)
Triggered by
[comment](https://github.com/ghostty-org/ghostty/issues/11729#issuecomment-4104386360)
from @mitchellh.

Vouch: @turbolent

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2026-03-21 20:57:07 +00:00
Mitchell Hashimoto
ed1397826b vt: persist VT stream state across vt_write calls (#11728)
Previously, every call to vt_write created a fresh ReadonlyStream with
new Parser and UTF8Decoder state. This meant escape sequences split
across write boundaries (e.g. ESC in one write, [27m in the next) would
lose parser state, causing the second write to start in ground state and
print the CSI parameters as literal text.

The C API now stores a persistent ReadonlyStream in the TerminalWrapper
struct, which is created when the Terminal is initialized. The vt_write
function feeds bytes through this stored stream, allowing it to maintain
parser state across calls. This change ensures that escape sequences
split across write boundaries are correctly parsed and rendered.
2026-03-21 11:24:15 -07:00
Mitchell Hashimoto
918840cf1d vt: persist VT stream state across vt_write calls
Previously, every call to vt_write created a fresh ReadonlyStream with
new Parser and UTF8Decoder state. This meant escape sequences split
across write boundaries (e.g. ESC in one write, [27m in the next)
would lose parser state, causing the second write to start in ground
state and print the CSI parameters as literal text.

The C API now stores a persistent ReadonlyStream in the TerminalWrapper
struct, which is created when the Terminal is initialized. The vt_write
function feeds bytes through this stored stream, allowing it to maintain
parser state across calls. This change ensures that escape sequences
split across write boundaries are correctly parsed and rendered.
2026-03-21 11:18:02 -07:00