Files
ghostty/example/wasm-vt
Mitchell Hashimoto 6479d90ca5 example/wasm-vt: use ghostty_type_json for struct layouts
Replace hardcoded byte offsets and struct sizes with dynamic lookups
from the ghostty_type_json API. On WASM load, the type layout JSON
is fetched once and parsed into a lookup table. Two helpers,
fieldInfo and setField, use this metadata to write struct fields at
the correct offsets with the correct types.

This removes the need to manually maintain wasm32 struct layout
comments and magic numbers for GhosttyTerminalOptions and
GhosttyFormatterTerminalOptions, so the example stays correct if
the struct layouts change.
2026-03-30 10:16:19 -07:00
..
2026-03-30 10:16:19 -07:00

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/