Files
ghostty-rs/crates/ghostty-cli/src/help.rs
T
ddidderr f2c4b40062 feat(cli): port ghostty +action CLI commands
Ports ZIG/src/cli into ghostty-cli: action detection/dispatch with
per-action --help, and the actions help, version, list-actions,
list-colors, list-keybinds, list-themes (plain listing plus an
interactive ratatui browser mirroring Ghostty's libvaxis UI),
show-config, validate-config, edit-config, crash-report (listing),
ssh-cache and boo (235 embedded frames).

Verified byte-for-byte against the installed Ghostty 1.3.1 for stdout,
stderr and exit codes of most actions, incl. tty output in a pty at
widths 20-200. Known differences: +list-colors --plain prints all 782
colors (Ghostty truncates at 617 because it never flushes), +version
has placeholder build info until build_info::set is wired up.

Deferred: list-fonts, show-face (need font discovery integration) and
new-window (needs GTK IPC); they return NotYetAvailable for now.

Test Plan:
- cargo test -p ghostty-cli (86 tests)
- cargo run -p ghostty-cli --example cli -- +list-keybinds --plain
  and diff against `ghostty +list-keybinds --plain`
2026-10-11 22:22:01 +02:00

94 lines
2.9 KiB
Rust

//! `+help` (ZIG/src/cli/help.zig).
use std::io::Write;
use ghostty_config::config_struct;
use crate::error::Error;
use crate::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: &[String]) -> Result<u8, Error> {
let mut opts = Options::default();
crate::parse_options(&mut opts, args)?;
let mut out = std::io::BufWriter::new(std::io::stdout().lock());
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"));
}
}