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:
1 parent
800fe5be5e
commit
33d15a2dc2
34 files changed
+14894
-1
No files matched your search
@@ -0,0 +1,104 @@
|
||||
//! Diagnostic messages produced while parsing configuration / CLI args.
|
||||
|
||||
use std::fmt;
|
||||
|
||||
/// A diagnostic message from parsing. This is used to provide additional
|
||||
/// human-friendly warnings and errors about the parsed data.
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Default)]
|
||||
pub struct Diagnostic {
|
||||
pub location: Location,
|
||||
pub key: String,
|
||||
pub message: String,
|
||||
}
|
||||
|
||||
impl Diagnostic {
|
||||
/// Write the full user-friendly diagnostic message to the writer.
|
||||
pub fn format(&self, writer: &mut dyn fmt::Write) -> fmt::Result {
|
||||
match &self.location {
|
||||
Location::None => {}
|
||||
Location::Cli(index) => write!(writer, "cli:{index}:")?,
|
||||
Location::File { path, line } => write!(writer, "{path}:{line}:")?,
|
||||
}
|
||||
|
||||
if !self.key.is_empty() {
|
||||
write!(writer, "{}: ", self.key)?;
|
||||
} else if self.location != Location::None {
|
||||
write!(writer, " ")?;
|
||||
}
|
||||
|
||||
write!(writer, "{}", self.message)
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for Diagnostic {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
self.format(f)
|
||||
}
|
||||
}
|
||||
|
||||
/// The possible locations for a diagnostic message. This is used
|
||||
/// to provide context for the message.
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Default)]
|
||||
pub enum Location {
|
||||
#[default]
|
||||
None,
|
||||
Cli(usize),
|
||||
File {
|
||||
path: String,
|
||||
line: usize,
|
||||
},
|
||||
}
|
||||
|
||||
/// The tag of a [`Location`] (Zig: `Location.Key`).
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum LocationKey {
|
||||
None,
|
||||
Cli,
|
||||
File,
|
||||
}
|
||||
|
||||
impl Location {
|
||||
#[must_use]
|
||||
pub fn key(&self) -> LocationKey {
|
||||
match self {
|
||||
Location::None => LocationKey::None,
|
||||
Location::Cli(_) => LocationKey::Cli,
|
||||
Location::File { .. } => LocationKey::File,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A list of diagnostics.
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Default)]
|
||||
pub struct DiagnosticList {
|
||||
list: Vec<Diagnostic>,
|
||||
}
|
||||
|
||||
impl DiagnosticList {
|
||||
pub fn append(&mut self, diag: Diagnostic) {
|
||||
self.list.push(diag);
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.list.is_empty()
|
||||
}
|
||||
|
||||
/// Zig: `empty()`.
|
||||
#[must_use]
|
||||
pub fn empty(&self) -> bool {
|
||||
self.list.is_empty()
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn items(&self) -> &[Diagnostic] {
|
||||
&self.list
|
||||
}
|
||||
|
||||
/// Returns true if there are any diagnostics for the given
|
||||
/// location type.
|
||||
#[must_use]
|
||||
pub fn contains_location(&self, location: LocationKey) -> bool {
|
||||
self.list.iter().any(|d| d.location.key() == location)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user