# Ghostty-rs Architecture Rust rewrite of Ghostty 1.3.1. Reference source: `../ghostty/` (Zig), referred to below as `ZIG/` (= `../../../ghostty`). Target platform: **Linux (GTK4 + libadwaita, OpenGL)**. macOS/Metal/CoreText, WASM, Windows and the embedded C API (`libghostty`) are out of scope. ## Crate map (workspace `crates/`) | Crate | Ports (ZIG/src/...) | Depends on | |---|---|---| | `ghostty-vt` | terminal/Parser, parse_table, UTF8Decoder, osc.zig + osc/*, csi, dcs, apc, sgr, color, x11_color, charsets, modes, ansi, device_status, mouse_shape, kitty/key, kitty/color, kitty/graphics_command, stream.zig | – | | `ghostty-unicode` | unicode/* (width, grapheme break, props) | – | | `ghostty-datastruct` | datastruct/* (split_tree, lru, circ_buf, blocking_queue, cache_table, ...) | – | | `ghostty-os` | os/* (xdg, homedir, shell, locale, passwd, env, open, desktop, resourcesdir, hostname, TempDir, uri, ...) | – | | `ghostty-input` | input/* (key, key_mods, keycodes, function_keys, key_encode, Binding, command, mouse, paste, kitty, Link) | vt | | `ghostty-config` | config/*, cli/args.zig, cli/CommaSplitter.zig, cli/diagnostics.zig | input, os, vt | | `ghostty-terminal` | terminal/ page, PageList, Screen, ScreenSet, Terminal, style, hyperlink, Tabstops, size, point, Selection, formatter, render, highlight, search/*, kitty/graphics_{image,storage,exec,unicode,render}, tmux/*, stream_readonly, StringMap, ref_counted_set, bitmap_allocator semantics | vt, unicode, datastruct | | `ghostty-font` | font/* (Metrics, sprite/*, Atlas, discovery via fontconfig, face via freetype, shaper via harfbuzz, Collection, CodepointResolver, SharedGrid(Set), opentype/*, nerd_font_attributes) | config, unicode, terminal | | `ghostty-renderer` | renderer/ generic, OpenGL (+ opengl/*), cell, cursor, image, link, size, State, Thread, Overlay, shadertoy, row, shaders/glsl | config, font, terminal | | `ghostty-termio` | termio/*, pty.zig, Command.zig, shell-integration resources | config, terminal, os | | `ghostty-core` | App.zig, Surface.zig, surface_mouse.zig, apprt/action.zig, apprt/structs.zig, apprt/surface.zig, global.zig, cli/* actions (+list-fonts, +show-config, ...) | everything below | | `ghostty-apprt-gtk` | apprt/gtk/* | core, config, input | | root `ghostty-rs` (bin `ghostty`) | main_ghostty.zig, build_config.zig | core, config, apprt-gtk | ## Key design decisions 1. **Safe Rust by default.** Workspace lint `unsafe_code = "forbid"`. Crates that must do FFI/syscalls (renderer GL loader, termio pty/fork, apprt-gtk) may override with `unsafe_code = "deny"` and `#[allow(unsafe_code)]` on minimal, `// SAFETY:`-commented items. Prefer safe wrapper crates (rustix, glow, gtk4-rs) over raw FFI. 2. **Pages without raw memory.** Ghostty's `page.zig` packs a page into one mmap'd buffer with offsets. In Rust a `Page` owns `Vec` + `Vec` (row-major, `cols` per row) plus per-page `RefCountedSet