Files
ghostty-rs/docs/rewrite/notes/compat-GC-helpgen.md
T
ddidderr 4787565397 feat: port GTK version fallbacks, helpgen, bench modes, CLI leftovers
- apprt-gtk: Ghostty's runtime+build-time version gating (at_least)
  with cargo features adw_1_3/adw_1_4/adw_1_5/gtk_4_16 (default on) and
  the fallbacks for older libraries: MessageDialog (adw < 1.5),
  clipboard dialog without SwitchRow, pre-Banner debug warning and
  child-exited widgets, the old about dialog, GTK 4.16 CSS error source
  bytes. The minimum stays GTK 4.14 / libadwaita 1.5 (Ghostty's floor).
  The root build links with -z lazy so version-gated symbols don't keep
  older libraries from loading.
- ghostty-helpgen (port of helpgen.zig) generates CLI action help and
  keybinding action docs from doc comments at build time, replacing the
  checked-in help/*.txt; +help and +list-actions --docs stay
  byte-identical to Ghostty 1.3.1.
- ghostty-bench: libc wcwidth mode and separate simd/table and
  uucode/table code paths like Zig.
- ghostty-cli: Windows branches of edit-config, list-colors,
  list-keybinds and boo; ssh-cache DiskCache flock locking (no-op on
  Windows, as in Zig) with an exclusivity test.

Test Plan:
- cargo test --workspace
- diff <(cargo run -q -- +list-actions --docs) \
  <(ghostty +list-actions --docs)
2026-10-12 06:38:33 +02:00

44 lines
2.1 KiB
Markdown

# compat-GC: helpgen (ZIG/src/helpgen.zig)
Zig generates help strings at build time from doc comments (`helpgen.zig`,
exposed as `help_strings`). The Rust port does the same instead of keeping
checked-in tables.
## Design
* New crate `crates/ghostty-helpgen` (no dependencies), used as a
`[build-dependencies]` of `ghostty-cli` and `ghostty-input`.
* `doc_lines`: port of `extractDocComments`/`findCommonPrefix` (strip
`///`, remove the common leading-space prefix of non-blank lines, keep
blank lines and code fences verbatim).
* `run_fn_doc`: doc comment of a module's `run` function (Zig `genActions`).
* `enum_variant_docs`: `///` docs per variant of an enum (Zig
`genKeybindActions`).
* `*_match`: emit Rust `match self { ... }` bodies with escaped literals.
* `ghostty-cli/build.rs` reads the variants of `enum Action` in
`src/ghostty.rs`, maps `ListFonts` -> `src/list_fonts.rs`, extracts the doc
of `pub fn run`, writes `$OUT_DIR/action_help.rs`; `Action::help_text`
`include!`s it. A missing doc comment fails the build (as in Zig).
The former `src/help/*.txt` files are deleted.
* `ghostty-input/build.rs` extracts the docs of every variant of
`enum Action` in `src/binding/action.rs` (now `///` instead of `//`),
writes `$OUT_DIR/keybind_action_docs.rs`, included by `ActionKey::docs`
(docs = lines joined by `\n` plus one trailing `\n`, as before;
`help_string` strips one).
* Config help already derives from field docs through `config_struct!`
(`ghostty-config/src/macros.rs`), so no generation was needed there.
* A line-based scanner is used rather than `syn`: it mirrors Zig's token
based approach (doc run + following item) and avoids a heavy build dep.
## Verification
Outputs of `+help`, `+list-actions [--docs]` and every `+<action> --help`
were captured before and after: byte identical. Differences vs
`/usr/bin/ghostty` exist only for `+version --help` and `+new-window --help`
(unchanged from the baseline).
## Tests
`ghostty-helpgen` unit tests (marker stripping, common prefix, blank lines,
code fences, `////`, run-doc and enum-variant extraction, escaping).