# Development ghosttyconf is written in Go with [Bubble Tea](https://github.com/charmbracelet/bubbletea) and [Lip Gloss](https://github.com/charmbracelet/lipgloss). It has no other runtime dependencies. Everything Ghostty-specific comes either from the embedded schema or from the `ghostty` command line. ## Building and testing ```sh make build # ./ghosttyconf make install # go install make test # go test ./... make schema # regenerate the option schema for the installed Ghostty make screenshots # regenerate docs/images (needs tmux and Ghostty) make dist # = ./build.sh: release binaries for all platforms into ./bin ``` The code builds on macOS, Linux and the BSDs. Automatic reload is implemented for macOS and Linux. Other platforms only save. ## Project layout | Path | Content | | --- | --- | | `main.go` | flags, startup, wiring | | `version.go`, `version.txt` | the version: `version.txt` is the released one, `build.sh` injects it | | `build.sh` | builds the release binaries into `./bin` | | `selfupdate.go` | `--update`, `--check-update` and the daily background check against the Gitea releases | | `internal/schema` | the option schema: kinds, categories, platform detection, value validation; `schema.json` is embedded | | `internal/config` | the comment- and layout-preserving config file model, atomic saving | | `internal/ghostty` | finding and running the `ghostty` binary (docs, themes, fonts, actions, validation), config paths, reload | | `internal/keybind` | trigger parsing and normalization, the merged binding set, decoding of recorded keys | | `internal/colors` | hex and X11 color names | | `internal/ui` | the Bubble Tea application: browser, editors, pickers, key binding manager, dialogs | | `tools/genschema` | generator for `internal/schema/schema.json` | | `tools/termsvg` | renders captured terminal screens as SVG (for the screenshots) | | `tools/screenshots.sh` | drives ghosttyconf in tmux and writes `docs/images/*.svg` | ## Versions and releases The version follows `MAJOR.MINOR.PATCH`. `version.txt` holds the version of the last release build. `build.sh` builds `bin/ghosttyconf--` for macOS and Linux on arm64 and amd64. The binaries are static (`CGO_ENABLED=0`) and stripped, and they carry the version via `-ldflags "-X main.Version=…"`. `make build` and `make install` use `version.txt` too. Only a plain `go build` reports the literal in `version.go`. ```sh ./build.sh # bump the patch number: 1.0.0 -> 1.0.1 VERSION=1.1.0 ./build.sh # or set the version explicitly ``` A release is made with [mgsh](https://git.micw.org/mike/mgsh): ```sh VERSION=1.1.0 ./build.sh mgsh push "version 1.1.0" # commit and push to the git server mgsh pushremote @micw # update the public mirror mgsh release @micw 1.1.0 "notes" # tag, publish, attach ./bin ``` `mgsh release` creates the annotated tag, pushes it and publishes the release on git.micw.org. Every regular file in `./bin` is attached to it. If the tag already exists with a longer annotation, that annotation becomes the release notes. `./bin` is not part of the repository. ### Self-update `selfupdate.go` is the copyable template from nscan (originally goca). Only its configuration block is specific to ghosttyconf: the repository URL, the asset name and `GHOSTTYCONF_NO_UPDATE_CHECK`. It relies on the release layout above, so keep these when changing the build or the release: - The tag is the bare version number. - The assets are named `ghosttyconf--`, exactly as `build.sh` names them. - `ghosttyconf --version` prints the version number. The downloaded binary is started with it, and the update is refused if the number is missing. - The release is neither a draft nor a prerelease. Gitea's `/releases/latest` skips both, so a prerelease is a way to publish without offering it as an update. The daily check starts the program again as `ghosttyconf --update-refresh` and doesn't wait for it. `main` takes that argument before the flags, so it stays out of the help. The note goes to `os.UserCacheDir()/ghosttyconf/update.json`. `tools/screenshots.sh` sets `GHOSTTYCONF_NO_UPDATE_CHECK=1`, so no update hint lands in a screenshot. The tests in `selfupdate_test.go` run against a fake Gitea built with `httptest` and never touch the network. ## The schema Ghostty's own documentation (`ghostty +show-config --default --docs`) contains names, defaults and descriptions, but not the *types* of options. Those come from Ghostty's source. `tools/genschema` reads `src/config/Config.zig` and: - maps Zig field types to editor kinds (bool, enum, flags, int, float, color, metric, duration, padding, path, theme, font, keybind, palette, …); - resolves enums, tagged unions and packed structs declared in the file to their values and flags; - uses `typeMap` for types from other files and `keyOverrides` for options whose type alone isn't specific enough; - adds documentation and defaults from `+show-config`; - sorts every option into one of the categories in `internal/schema/categories.go`, and detects platform-specific options from their names and documentation; - reads the `compatibility` table into `compat`: renamed keys with their new name, and for each handler function the old values it compares against and the options it sets. The editor uses it to explain old keys and values instead of reporting them as errors. The result is embedded in the binary. At startup, the documentation and defaults are refreshed from the installed Ghostty, so they always match the user's version. If an option is missing from the embedded schema, it is still editable, as a text value. ### Updating for a new Ghostty release ```sh make schema # = go run ./tools/genschema ``` This detects the installed Ghostty version, downloads `src/config/Config.zig` of that tag from GitHub, and rewrites `internal/schema/schema.json`. Offline, or for unreleased versions: ```sh go run ./tools/genschema -zig path/to/Config.zig -docs docs.txt -version 1.4.0 ``` Afterwards, run `make test` and check the generator's warnings. Unknown types need an entry in `typeMap`. A compatibility warning means the table or its handlers changed shape and `parseCompat` needs a look. Then check that every `ghostty` command ghosttyconf runs is still understood: ```sh GHOSTTYCONF_LIVE_TEST=1 go test -run Live -v ./internal/ghostty ``` New options land in **Advanced** unless `internal/schema/categories.go` places them. `git diff internal/schema/schema.json` shows what changed. ## The config file model `internal/config` parses the file into lines: entries (`key = value`), comments and blank lines, each with its original text. A line that isn't edited is written back byte for byte. - `Set`/`SetAll` compute a minimal edit script (longest common subsequence) between the old and new values of a key. Unchanged entries keep their place and formatting, changed ones are rewritten in place, and new ones are inserted after the last entry of the same key. - `Save` writes a temporary file next to the target (resolving symlinks), preserves permissions, optionally writes `.bak`, and renames the temporary file over the target. - `ChangedOnDisk` compares the modification time, so a file changed by another program is never overwritten silently. ## Key bindings `internal/keybind` mirrors Ghostty's own parser (`src/input/Binding.zig`): - `Split` separates trigger and action the way Ghostty does (`=` followed by `=` or `+` belongs to the trigger, so `super+==…` works). - `ParseTrigger` and `Normalize` understand modifier aliases (`cmd`, `opt`, `control`), key names from `key.zig`, legacy names (`grave_accent`, `up`), sequences (`a>b`) and prefixes (`global:`, `all:`, `unconsumed:`, `performable:`). The merged view uses the normalized form, so different spellings of the same trigger are recognized as one. - `Set` combines Ghostty's default bindings with the user's entries (including `clear`, `unbind` and `chain=`) into the *effective* bindings and their sources. `Change`, `Unbind` and `Restore` turn edits in the UI into the smallest list of config entries. ### Recording While recording, the UI sends `CSI > 9 u` (push the kitty keyboard protocol with "report all keys as escape codes") and `CSI ? u` (query). Ghostty then reports every key as `CSI code ; mods u`, including super combinations. Bubble Tea v1 doesn't know these sequences and passes them on as an unexported message type, which `ui/term.go` reads by reflection. `keybind.DecodeCSI` turns them into triggers. The protocol is popped again when recording ends and when the program exits. This depends on a Bubble Tea internal. `TestRawSequenceFromBubbleTea` in `internal/ui/term_test.go` feeds a real sequence through Bubble Tea's input parser and fails if an upgrade changes how such sequences arrive. ## Reloading | File | Mechanism | | --- | --- | | `reload_darwin.go` | `osascript`: `perform action "reload_config"` on Ghostty's first terminal, addressed by bundle id, only if Ghostty is running; translates AppleScript errors (-1743 permission, -1708 scripting disabled) into readable messages | | `reload_linux.go` | `SIGUSR2` to every `ghostty` process of the user found in `/proc`, skipping CLI invocations (`ghostty +…`), which would be terminated by the signal | | `reload_other.go` | not supported; the status line tells the user to reload manually | ## Screenshots The images in `docs/images` are generated, not drawn: ```sh make screenshots # or: THEME="TokyoNight" ./tools/screenshots.sh ``` The script builds ghosttyconf and `tools/termsvg`, then runs ghosttyconf in a detached tmux session (144×34) with a demo config and a temporary `$HOME`. It sends key presses (kitty sequences for recorded keys) and captures each screen with `tmux capture-pane -e`. `termsvg` renders the captures as SVG, taking colors from a Ghostty theme file. Box drawing and block characters are drawn as shapes so borders connect, and text runs are pinned to the cell grid, so the images look the same with any monospace font.