Files
ghostty-rs/crates/ghostty-cli/src/list_actions.rs
T
ddidderr 654acd55e6 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
2026-10-12 15:15:18 +02:00

65 lines
1.8 KiB
Rust

//! `+list-actions` (ZIG/src/cli/list_actions.zig).
use std::io::Write;
use ghostty_config::config_struct;
use crate::error::Error;
config_struct! {
pub struct Options {
/// If `true`, print out documentation about the action associated with the
/// keybinds.
"docs" => docs: bool = false,
}
}
cli_options!(Options, help);
/// The `list-actions` command is used to list all the available keybind
/// actions for Ghostty. These are distinct from the CLI Actions which can
/// be listed via `+help`
///
/// Flags:
///
/// * `--docs`: will print out the documentation for each action.
pub fn run(args: &[impl AsRef<[u8]>]) -> Result<u8, Error> {
let mut opts = Options::default();
crate::parse_options(&mut opts, args)?;
let out = generate_plaintext(opts.docs);
let mut stdout = crate::zig_writer::ZigWriter::new(crate::zig_writer::stdout_sink(), 4096);
stdout.write_all(out.as_bytes())?;
stdout.flush()?;
Ok(0)
}
/// `helpgen_actions.generate(.plaintext, show_docs)`.
#[must_use]
pub fn generate_plaintext(show_docs: bool) -> String {
ghostty_input::helpgen_actions::generate_string(
ghostty_input::helpgen_actions::Format::Plaintext,
show_docs,
)
}
#[cfg(test)]
mod tests {
#![allow(clippy::unwrap_used)]
use super::*;
#[test]
fn names_only() {
let s = generate_plaintext(false);
assert!(s.starts_with("ignore\nunbind\ncsi\n"));
assert!(!s.contains(':'));
}
#[test]
fn docs_have_no_stray_blank_lines_between_actions() {
let s = generate_plaintext(true);
assert!(s.starts_with("\nignore:\n Ignore this key combination.\n"));
assert!(s.contains(" respectively.\n\njump_to_prompt:\n"));
assert!(s.ends_with('\n'));
}
}