Files
ghostty-rs/crates/ghostty-apprt/src/ipc.rs
T
ddidderr 672e8a4ae1 refactor(config): parse config values from raw bytes like Zig
Zig parses config values (cli/args.zig, Config.zig field parsers,
config/string.zig) from raw byte slices, and each field type decides
whether it requires UTF-8 (InvalidValue otherwise) or stores bytes. The
port escape-encoded raw bytes into Strings at the line reader and let
fields parse the escaped text, so fields could observe encoding
artifacts; successive audits kept finding such leaks (RV5-RV8).

Field parsers now receive the original bytes: text fields validate UTF-8
where Zig does, byte/path fields store bytes (EncodedOs/OsString). This
resolves all 9 RV8 findings (docs/rewrite/notes/review-rv8-codex.md),
each with a regression test: Windows path conversion fails with
BadPathName instead of substituting U+FFFD; Windows process launch uses
strict UTF-8 like Zig's Command; the WTF-8 decoder accepts paired-
surrogate encodings like Zig; literal U+FDD0 Unicode key triggers;
selection-word-chars and clipboard-codepoint-map reject invalid UTF-8;
font style / codepoint-map family names use original bytes; C title
actions forward bytes; D-Bus new-window/Flatpak conversions match Zig.
Design, sweep and validation: docs/rewrite/notes/final-bytes-refactor.md.

Also moves the bundled iTerm2-Color-Schemes license out of
resources/themes/ so +list-themes no longer lists it as a theme
(output is now byte-identical to Ghostty 1.3.1).

Done by Codex (gpt-6-astra), reviewed and verified by the orchestrator.

Test Plan:
- cargo test --workspace --no-fail-fast (3428 passed, exit 0)
- just check-macos (both), just check-windows, just check-wasm
- +show-config --default --docs, +list-keybinds, +list-actions --docs,
  +list-themes --plain compared with /usr/bin/ghostty
2026-10-12 11:57:01 +02:00

82 lines
2.1 KiB
Rust

//! Inter-process Communication to a running Ghostty instance from a separate
//! process (port of `ipc.zig`). The transport (D-Bus) lives in apprt-gtk.
/// Errors from IPC.
#[derive(Debug, Clone, Copy, PartialEq, Eq, thiserror::Error)]
pub enum Error {
/// The IPC failed. If a function returns this error, it's expected that
/// an a more specific error message will have been written to stderr (or
/// otherwise shown to the user in an appropriate way).
#[error("IPC failed")]
IpcFailed,
}
/// Which instance to talk to.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Target {
/// Open up a new window in a custom instance of Ghostty.
Class(String),
/// Detect which instance to open a new window in.
Detect,
}
/// The arguments to pass to Ghostty as the command.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct NewWindow {
/// A list of command arguments to launch in the new window. If this is
/// `None` the command configured in the config or the user's default
/// shell should be launched.
///
/// It is an error for this to be `Some`, but zero length.
pub arguments: Option<Vec<Vec<u8>>>,
}
/// IPC actions.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Action {
/// The arguments to pass to Ghostty as the command.
NewWindow(NewWindow),
}
/// Mirrors `Action.Key`.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ActionKey {
NewWindow,
}
impl Action {
#[must_use]
pub fn key(&self) -> ActionKey {
match self {
Action::NewWindow(_) => ActionKey::NewWindow,
}
}
}
impl Target {
#[must_use]
pub fn is_detect(&self) -> bool {
matches!(self, Target::Detect)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn action_key() {
let a = Action::NewWindow(NewWindow {
arguments: Some(vec!["a".into()]),
});
assert_eq!(a.key(), ActionKey::NewWindow);
}
#[test]
fn target_variants() {
assert!(Target::Detect.is_detect());
assert!(!Target::Class("x".into()).is_detect());
}
}