fix: +show-face u21/UTF-8 semantics, Zig output buffering, isAbsolute

Resolves RV14 (docs/rewrite/notes/review-rv14-codex.md, final-Z17.md):
- +show-face --cp parses as u21 (new U21 field type): out-of-range
  values give an invalid-value diagnostic and exit 1 instead of a panic;
  --string accepts raw bytes and fails with error.InvalidUtf8 after the
  codepoint lookup like Zig.
- CLI actions write through ZigWriter, a model of Zig 0.15's buffered
  File.writer (fixed buffer, drain on overflow, explicit flush), so
  stdout/stderr interleave in Zig's flush order (+show-face, help,
  version, validate-config, show-config, list-*, ssh-cache, crash-report,
  edit-config, new-window).
- Zig 0.15.2 std.fs.path.isAbsolute port (Windows: \theme and /theme are
  absolute) replaces Path::is_absolute at every Zig isAbsolute site.
- io_uring is available iff a 256-entry ring can be created, like
  libxev; the reactor falls back to IORING_OP_TIMEOUT without EXT_ARG.
- Windows basename (`λ:theme`) verified against 0.15.2 (test added).

Test Plan:
- cargo test --workspace --no-fail-fast
- diff +show-face outputs (pipe) against /usr/bin/ghostty
This commit is contained in:
ddidderr committed 2026-10-12 15:15:18 +02:00
1 parent 3aab04bdce
commit 654acd55e6
26 files changed
+574 -55

No files matched your search

+47
View File
@@ -605,6 +605,30 @@ impl_int_field!(
isize => |_| CValue::Unsupported
);
/// Zig `u21` (a Unicode scalar range integer, `0..=0x1F_FFFF`).
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub struct U21(pub u32);
impl U21 {
pub const MAX: u32 = 0x1f_ffff;
}
impl ConfigField for U21 {
fn parse_bytes(&mut self, value: Option<&[u8]>) -> Result<(), ArgError> {
let v = value.ok_or(ArgError::ValueRequired)?;
let n = ghostty_os::zig_fmt::parse_int::<u32>(v, 0).map_err(|_| ArgError::InvalidValue)?;
if n > Self::MAX {
return Err(ArgError::InvalidValue);
}
*self = U21(n);
Ok(())
}
fn format_entry(&self, f: &mut EntryFormatter<'_>) -> fmt::Result {
writeln!(f.writer, "{} = {}", f.name, self.0)
}
}
macro_rules! impl_float_field {
($($t:ty => $cv:expr),*) => {$(
impl ConfigField for $t {
@@ -1021,6 +1045,29 @@ mod tests {
}
}
config_struct! {
pub struct Cp {
"cp" => cp: Option<U21> = None,
}
}
#[test]
fn u21_field_matches_zig_range() {
let mut c = Cp::raw_default();
c.parse_field("cp", Some("0x1FFFFF")).unwrap();
assert_eq!(c.cp, Some(U21(0x1f_ffff)));
c.parse_field("cp", Some("0b1000001")).unwrap();
assert_eq!(c.cp, Some(U21(65)));
for bad in ["0x200000", "4294967295", "99999999999999999999", "-1", "x"] {
assert_eq!(
c.parse_field("cp", Some(bad)),
Err(ArgError::InvalidValue),
"{bad}"
);
}
assert_eq!(c.parse_field("cp", None), Err(ArgError::ValueRequired));
}
config_enum! {
pub enum OneTwo { One => "one", Two => "two" }
}
+4 -2
View File
@@ -3935,7 +3935,8 @@ impl Config {
///
/// `path` must be resolved and absolute.
pub fn load_file(&mut self, path: &EncodedOs) -> Result<(), Error> {
assert!(path.to_path()?.is_absolute());
path.to_path()?;
assert!(path.is_zig_absolute());
let file = match crate::file_load::open(path) {
Ok(f) => f,
Err(crate::file_load::OpenFileError::NotAFile) => {
@@ -4260,7 +4261,8 @@ impl Config {
// All paths should already be absolute at this point because
// they're fixed up after each load.
assert!(path.to_path()?.is_absolute());
path.to_path()?;
assert!(path.is_zig_absolute());
// We must only load a unique file once
if !loaded.insert(path.clone()) {
+1 -1
View File
@@ -163,7 +163,7 @@ pub fn open(path: &EncodedOs) -> Result<File, OpenFileError> {
log::warn!("invalid config path: {err}");
OpenFileError::FileOpenFailed
})?;
assert!(real.is_absolute());
assert!(path.is_zig_absolute());
let file = File::open(&real).map_err(|err| {
if err.kind() == std::io::ErrorKind::NotFound {
+5 -2
View File
@@ -112,12 +112,15 @@ impl Path {
pub fn expand(&mut self, base: &EncodedOs, diags: &mut DiagnosticList) -> std::io::Result<()> {
// Filesystem calls use the decoded OS paths.
let base_path = base.to_path()?;
assert!(base_path.is_absolute());
assert!(base.is_zig_absolute());
let path = self.path().clone();
// If it is already absolute we can ignore it.
if path.is_empty() || path.to_path()?.is_absolute() {
if path.is_empty() || {
path.to_path()?;
path.is_zig_absolute()
} {
return Ok(());
}
+16 -1
View File
@@ -229,7 +229,7 @@ pub fn open(
let theme_text = theme.as_encoded();
// Absolute themes are loaded a different path.
if theme_path.is_absolute() {
if theme.is_zig_absolute() {
let file = open_absolute(theme, diags)?;
if !check_regular(&file, theme_text, diags) {
return None;
@@ -446,6 +446,21 @@ mod tests {
assert_eq!(zig_basename("./"), ".");
}
#[test]
fn windows_basename_matches_zig_0_15_2() {
// The drive colon is recognized only at byte index 1.
assert_eq!(basename_windows("\u{3bb}:theme"), "\u{3bb}:theme");
assert_eq!(
basename_windows("light:\u{3bb}:theme"),
"light:\u{3bb}:theme"
);
assert_eq!(basename_windows("1:theme"), "theme");
assert_eq!(basename_windows("c:"), "");
assert_eq!(basename_windows("a\\b/c\\"), "c");
assert_eq!(basename_windows("\\"), "");
assert_eq!(basename_windows("theme"), "theme");
}
#[test]
fn dot_theme_names_are_directories() {
let dir = std::env::temp_dir().join(format!("ghostty-theme-dot-{}", std::process::id()));