feat(termio): port pty, child command spawning, shell integration

Ports the parts of Ghostty's IO layer that don't depend on the terminal:
- pty.zig: pty pair, window size, mode, child-side setsid/TIOCSCTTY;
  master is CLOEXEC with IUTF8 set
- Command.zig: fork/execvpe with Ghostty's exact child setup (stdio
  dup2, best-effort chdir, rlimit restore, os/runtime pre-exec hooks,
  cgroup handling) and exit status decoding
- shell_integration.zig for bash/zsh/fish/elvish/nushell plus feature
  flags; scripts copied verbatim to resources/shell-integration/
- terminfo generator for xterm-ghostty, byte-identical to Zig's encode
  output (golden file produced with the real Zig code)

This crate opts into unsafe_code = "deny" (fork/exec need it) with
allow + SAFETY comments on minimal items.

Integration left: config-derived option types are local stand-ins;
cgroup D-Bus scope creation is a closure hook; Exec/Termio/Thread/
stream_handler wait for ghostty-terminal. Pty now closes both fds on
drop (Zig never auto-closed the slave) - to re-check when wiring Exec.

Test Plan:
- cargo test -p ghostty-termio (52 tests, incl. real pty spawn test
  expecting "hi\r\n31 97\r\n" from `echo hi; stty size`)
This commit is contained in:
ddidderr committed 2026-10-11 22:06:51 +02:00
1 parent 668c236291
commit 09cbe3bc97
21 files changed
+7120 -28

No files matched your search

+24
View File
@@ -1 +1,25 @@
//! ghostty-termio: see docs/rewrite/ARCHITECTURE.md for the module map.
//!
//! Ported so far (Linux only): `pty.zig`, `Command.zig`,
//! `termio/shell_integration.zig`, the `terminfo/*` source generator.
//! See `docs/rewrite/notes/ghostty-termio-IO1.md`.
//!
//! This crate may use limited `unsafe` (fork/exec in `command`, a few
//! async-signal-safe libc calls in `pty`); everything else is safe.
#![cfg_attr(
test,
allow(
clippy::unwrap_used,
clippy::assert_is_empty,
clippy::items_after_statements
)
)]
pub mod command;
pub mod pty;
pub mod shell_integration;
pub mod terminfo;
pub use command::Command;
pub use pty::{Pty, Winsize};