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)
This commit is contained in:
ddidderr committed 2026-10-12 06:38:33 +02:00
1 parent cd86fe92a8
commit f2252bb165
51 files changed
+2426 -1621

No files matched your search

+42 -2
View File
@@ -31,13 +31,36 @@ pub struct CssProviders {
}
fn at_least_gtk(major: u32, minor: u32) -> bool {
(gtk::major_version(), gtk::minor_version()) >= (major, minor)
crate::gtk_version::runtime_at_least(major, minor, 0)
}
/// Log a CSS parsing error (Zig: `signalCssParsingError`).
fn log_parsing_error(section: &gtk::CssSection, err: &glib::Error) {
let location = section.to_str();
log::warn!("css parsing failed at {location}: {err}");
// GTK >= 4.16 can also hand us the offending source bytes.
#[cfg(feature = "gtk_4_16")]
if crate::gtk_version::at_least(4, 16, 0)
&& let Some(bytes) = section.bytes()
{
log::warn!("{}", parsing_error_message(&location, err, Some(&bytes)));
return;
}
log::warn!("{}", parsing_error_message(&location, err, None));
}
/// Builds the log line for [`log_parsing_error`]; with `data` the source
/// bytes follow on their own line (`css parsing failed at {s}: {s} {d} {s}\n{s}`).
fn parsing_error_message(location: &str, err: &glib::Error, data: Option<&[u8]>) -> String {
let base = format!(
"css parsing failed at {location}: {} {} {}",
err.domain().as_str(),
err.code(),
err.message(),
);
match data {
Some(data) => format!("{base}\n{}", String::from_utf8_lossy(data)),
None => base,
}
}
fn new_provider() -> gtk::CssProvider {
@@ -330,4 +353,21 @@ mod tests {
assert!(runtime_css(&c, true).contains("--ghostty-bg"));
assert!(runtime_css(&c, false).contains("windowhandle:backdrop"));
}
#[test]
fn parsing_error_message_includes_source_bytes() {
let err = glib::Error::with_domain(
glib::Quark::from_str("gtk-css-parser-error-quark"),
7,
"bad",
);
assert_eq!(
parsing_error_message("<data>:1:2", &err, None),
"css parsing failed at <data>:1:2: gtk-css-parser-error-quark 7 bad"
);
assert_eq!(
parsing_error_message("<data>:1:2", &err, Some(b"a { b }")),
"css parsing failed at <data>:1:2: gtk-css-parser-error-quark 7 bad\na { b }"
);
}
}