mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-09-14 18:01:58 +00:00
Replace a bunch of type-specific Wasm allocation functions with a generic byte allocator and reusable opaque out-parameters for pointers. This makes it a lot more ergonomic (relatively) to use the Wasm interface and removes a dozen or so exports. This also updates the `ghostty_type_json` `abi` field with a maximum alignment value that host sides can use to keep every allocation aligned properly, easily, without hardcoding numbers. This adds a test to verify this all works as intended and runs in CI.
WebAssembly VT Terminal Example
This example demonstrates how to use the Ghostty VT library from WebAssembly to initialize a terminal, write VT-encoded data to it, and format the terminal contents as plain text.
Building
First, build the WebAssembly module:
zig build -Demit-lib-vt -Dtarget=wasm32-freestanding -Doptimize=ReleaseSmall
This will create zig-out/bin/ghostty-vt.wasm.
Running
Important: You must serve this via HTTP, not open it as a file directly.
Browsers block loading WASM files from file:// URLs.
From the root of the ghostty repository, serve with a local HTTP server:
# Using Python (recommended)
python3 -m http.server 8000
# Or using Node.js
npx serve .
# Or using PHP
php -S localhost:8000
Then open your browser to:
http://localhost:8000/example/wasm-vt/