$ show ghostty-org/ghostty
Ghostty is a fast, native, feature-rich terminal emulator targeting macOS (SwiftUI/Metal) and Linux (GTK), with an embeddable C library, libghostty. The core is written in Zig, providing a complete VT parser, screen management, scrollback, selection, search, Kitty graphics protocol, and snapshot/restore. The macOS frontend uses SwiftUI and AppKit for window management, tabs, splits, quick terminal overlay, command palette, AppleScript, App Intents, and Sparkle-based updates. The Linux frontend uses GTK with Wayland/X11 support. The architecture is modular: a platform-independent terminal engine (src/terminal/) communicates with platform-specific app runtimes (src/apprt/) via a callback-based effects interface. The renderer supports Metal (macOS) and OpenGL (Linux) with SIMD-optimized text layout and custom font sprite drawing for powerline, box drawing, and Nerd Font glyphs. External dependencies include fontconfig, freetype, harfbuzz, oniguruma, libpng, and stb_image, all vendored and minimized. The build system uses Zig with Nix and CMake support. The library is designed for embedding, with examples in C, C++, Swift, Zig, and WebAssembly.
The LLM identified 5 files worth highlighting for reuse:
A generic binary tree data structure for managing split panes. Supports insert, remove, replace, resize, equalize, spatial navigation (up/down/left/right), focus tracking, and Codable serialization. It is self-contained (only imports std and a comparison helper) and can be extracted for any split-view UI in any Zig project.
Implements a binary snapshot format for terminal state with CRC32C integrity checks, incremental encode/decode, and support for continuation markers (READY/FINISH). The format is self-describing with typed records (page, style, hyperlink, grid, etc.). Reusable for any application needing crash-safe, incremental state persistence.
SIMD-accelerated Unicode codepoint width classification using the Highway library. Provides compile-time dispatch for x86 (SSSE3, AVX2, AVX512) and ARM (NEON). Implements East Asian Width, zero-width, and non-spacing mark detection via generated lookup tables. Reusable in any text rendering pipeline needing fast width computation.
Implements an incremental search algorithm over a sliding window of terminal pages. Supports needle matching across scrollback and active screen, with tick/feed split for threading. Handles screen switches, resize, and page pruning. Reusable for any text search over a paged data structure.
A typed configuration system that loads from files, CLI arguments, and recursive includes. Provides compile-time generated accessors for all settings (window, font, keybindings, etc.) with validation and error reporting. The pattern of generating typed config from a template is reusable for any application needing robust, extensible configuration.