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
93 lines
2.9 KiB
Rust
93 lines
2.9 KiB
Rust
//! `+help` (ZIG/src/cli/help.zig).
|
|
|
|
use std::io::Write;
|
|
|
|
use ghostty_config::config_struct;
|
|
|
|
use crate::{error::Error, ghostty::Action};
|
|
|
|
config_struct! {
|
|
// Note that this options struct doesn't implement the `help` decl like other
|
|
// actions. That is because the help command is special and wants to handle its
|
|
// own logic around help detection.
|
|
pub struct Options {
|
|
/// This must be registered so that it isn't an error to pass `--help`
|
|
"help" => help: bool = false,
|
|
}
|
|
}
|
|
cli_options!(Options);
|
|
|
|
/// The `help` command shows general help about Ghostty. Recognized as either
|
|
/// `-h, `--help`, or like other actions `+help`.
|
|
///
|
|
/// You can also specify `--help` or `-h` along with any action such as
|
|
/// `+list-themes` to see help for a specific action.
|
|
pub fn run(args: &[impl AsRef<[u8]>]) -> Result<u8, Error> {
|
|
let mut opts = Options::default();
|
|
crate::parse_options(&mut opts, args)?;
|
|
|
|
let mut out = crate::zig_writer::ZigWriter::new(crate::zig_writer::stdout_sink(), 2048);
|
|
write_help(&mut out)?;
|
|
out.flush()?;
|
|
Ok(0)
|
|
}
|
|
|
|
/// Write the general help text.
|
|
pub fn write_help(stdout: &mut dyn Write) -> std::io::Result<()> {
|
|
stdout.write_all(
|
|
b"Usage: ghostty [+action] [options]
|
|
|
|
Run the Ghostty terminal emulator or a specific helper action.
|
|
|
|
If no `+action` is specified, run the Ghostty terminal emulator.
|
|
All configuration keys are available as command line options.
|
|
To specify a configuration key, use the `--<key>=<value>` syntax
|
|
where key and value are the same format you'd put into a configuration
|
|
file. For example, `--font-size=12` or `--font-family=\"Fira Code\"`.
|
|
|
|
To see a list of all available configuration options, please see
|
|
the `src/config/Config.zig` file. A future update will allow seeing
|
|
the list of configuration options from the command line.
|
|
|
|
A special command line argument `-e <command>` can be used to run
|
|
the specific command inside the terminal emulator. For example,
|
|
`ghostty -e top` will run the `top` command inside the terminal.
|
|
|
|
On macOS, launching the terminal emulator from the CLI is not
|
|
supported and only actions are supported. Use `open -na Ghostty.app`
|
|
instead, or `open -na ghostty.app --args --foo=bar --baz=quz` to pass
|
|
arguments.
|
|
|
|
Available actions:
|
|
|
|
",
|
|
)?;
|
|
|
|
for action in Action::ALL {
|
|
writeln!(stdout, " +{}", action.name())?;
|
|
}
|
|
|
|
stdout.write_all(
|
|
b"
|
|
Specify `+<action> --help` to see the help for a specific action,
|
|
where `<action>` is one of actions listed above.
|
|
",
|
|
)?;
|
|
Ok(())
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
#![allow(clippy::unwrap_used)]
|
|
use super::*;
|
|
|
|
#[test]
|
|
fn help_lists_actions() {
|
|
let mut buf = Vec::new();
|
|
write_help(&mut buf).unwrap();
|
|
let s = String::from_utf8(buf).unwrap();
|
|
assert!(s.contains("Available actions:\n\n +version\n +help\n +list-fonts\n"));
|
|
assert!(s.ends_with("where `<action>` is one of actions listed above.\n"));
|
|
}
|
|
}
|