feat(config): port the configuration system and CLI argument parser

Ports ZIG/src/config (minus C/WASM APIs) and cli/{args,CommaSplitter,
diagnostics}.zig into ghostty-config:
- all 202 options with exact names, types, defaults and verbatim docs,
  declared through one config_struct! macro; Zig's comptime reflection is
  replaced by the ConfigField/CliTarget traits
- loading: default XDG files, -e, config-file includes (optional '?',
  cycle detection), themes incl. light:/dark: pairs, conditional config,
  replay, finalize() derived defaults, clone/changed diffing for reload
- Linux/GTK default keybinds built on ghostty_input::binding::Set
- formatter producing +show-config output

Verified against the installed Ghostty 1.3.1: `+show-config --default`
and `--default --docs` match byte for byte (except gtk-opengl-debug,
which differs between debug/release builds), as do two complex loaded
configs.

Open items (docs/rewrite/notes/ghostty-config.md): url regex needs an
Oniguruma-compatible engine (onig) in the renderer; some font/terminal
types are local copies awaiting integration; KeyRemapSet equality is
order sensitive unlike Zig.

Test Plan:
- cargo test -p ghostty-config (255 tests)
- compare `ghostty +show-config --default --docs` with our formatter
This commit is contained in:
ddidderr committed 2026-10-11 22:00:12 +02:00
1 parent 47b479dcfb
commit 67367dcaf5
34 files changed
+14894 -1

No files matched your search

+83
View File
@@ -0,0 +1,83 @@
//! `ConfigField` implementations for types owned by `ghostty-input`
//! (the input crate cannot depend on the config crate).
use crate::cli_args::{ArgError, ConfigField};
use crate::formatter::EntryFormatter;
use ghostty_input::{KeyRemapSet, OptionAsAlt};
use std::fmt;
impl ConfigField for KeyRemapSet {
fn parse_cli(&mut self, value: Option<&str>) -> Result<(), ArgError> {
self.parse_cli(value).map_err(|_| ArgError::InvalidValue)
}
fn format_entry(&self, f: &mut EntryFormatter<'_>) -> fmt::Result {
let entries = self.format_entries();
if entries.is_empty() {
return writeln!(f.writer, "{} = ", f.name);
}
for e in entries {
f.format_entry(&e)?;
}
Ok(())
}
}
impl ConfigField for OptionAsAlt {
const VALID_VALUES: Option<&'static [&'static str]> = None;
fn parse_cli(&mut self, value: Option<&str>) -> Result<(), ArgError> {
let v = value.ok_or(ArgError::ValueRequired)?;
*self = match v {
"false" => OptionAsAlt::False,
"true" => OptionAsAlt::True,
"left" => OptionAsAlt::Left,
"right" => OptionAsAlt::Right,
_ => return Err(ArgError::InvalidValue),
};
Ok(())
}
fn format_entry(&self, f: &mut EntryFormatter<'_>) -> fmt::Result {
let s = match self {
OptionAsAlt::False => "false",
OptionAsAlt::True => "true",
OptionAsAlt::Left => "left",
OptionAsAlt::Right => "right",
};
writeln!(f.writer, "{} = {}", f.name, s)
}
}
#[cfg(test)]
#[allow(clippy::unwrap_used)]
mod tests {
use super::*;
fn fe<T: ConfigField>(name: &str, v: &T) -> String {
let mut s = String::new();
crate::formatter::format_entry(name, v, &mut s).unwrap();
s
}
#[test]
fn remap_set_format_entry_empty() {
assert_eq!(fe("key-remap", &KeyRemapSet::default()), "key-remap = \n");
}
#[test]
fn remap_set_format_entry_values() {
let mut set = KeyRemapSet::default();
ConfigField::parse_cli(&mut set, Some("ctrl=super")).unwrap();
let out = fe("key-remap", &set);
assert!(out.starts_with("key-remap = left_ctrl=left_super\n"));
}
#[test]
fn option_as_alt_roundtrip() {
let mut v = OptionAsAlt::default();
v.parse_cli(Some("left")).unwrap();
assert_eq!(fe("a", &v), "a = left\n");
assert_eq!(v.parse_cli(Some("x")), Err(ArgError::InvalidValue));
}
}