initial commit [141.14.140.180,mike]

This commit is contained in:
mike committed 2026-10-22 13:21:28 +02:00
commit 156bb18c91
50 files changed
+13466

No files matched your search

+143
View File
@@ -0,0 +1,143 @@
# 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)
```
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 |
| `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` |
## 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.
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 about unknown
types. Those types need an entry in `typeMap`.
## 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 `<file>.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.