feat(termio): port the IO thread, Exec backend and stream handler

Ports the remainder of ZIG/src/termio: Options, backend, message,
mailbox, Termio, Thread, Exec and stream_handler.

Threading model (replacing libxev): the IO thread owns Termio and runs a
single poll(2) loop over the mailbox eventfd, a stop eventfd, the child
pidfd and pty POLLOUT, driving Ghostty's timers (25 ms resize
coalescing, 1 s synchronized-output, 15 ms selection scroll, 200 ms
termios polling). A separate pty read thread locks the shared renderer
state and feeds the terminal. Renderer and surface interaction go
through RendererMailbox/SurfaceMailbox traits.

The stream handler answers all queries (DA, DSR, XTVERSION, DECRQM,
OSC color queries, XTGETTCAP, DECRQSS, ...) and forwards titles, pwd,
OSC 52, notifications, progress and bell as surface messages. Zig
unlocks the renderer mutex when a mailbox is full; here overflow goes to
an ordered outbox flushed after the locks drop.

IO1's local stand-ins are replaced with the real config types.

Open: RendererState lives in termio for now (renderer State.zig is
being ported); kitty graphics replies and tmux viewer are not hooked up;
wait-after-command lives in Surface (core); Flatpak stop path needs a
ghostty-os change.

Test Plan:
- cargo test -p ghostty-termio (102 unit + 21 end-to-end tests on a
  real pty, incl. backpressure, DA1 replies, resize coalescing, exits)
This commit is contained in:
ddidderr committed 2026-10-11 22:58:48 +02:00
1 parent 4a40470746
commit 6629fb0822
19 files changed
+6170 -195

No files matched your search

+47
View File
@@ -0,0 +1,47 @@
//! The options that are used to configure a terminal IO implementation
//! (`termio/Options.zig`).
use std::sync::Arc;
use ghostty_config::config::Config;
use ghostty_renderer::size::Size;
use crate::backend::Backend;
use crate::mailbox::Mailbox;
use crate::sinks::{RendererMailbox, SurfaceMailbox};
use crate::termio::DerivedConfig;
use crate::wakeup::Wakeup;
/// See the module docs.
pub struct Options<'a> {
/// All size metrics for the terminal.
pub size: Size,
/// The full app configuration. This is only available during
/// initialization; any values needed later must be copied.
pub full_config: &'a Config,
/// The derived configuration for this termio implementation.
pub config: DerivedConfig,
/// The backend for termio that implements where reads/writes are sourced.
pub backend: Backend,
/// The mailbox for the terminal. This is how messages are delivered.
/// If you're using `termio::Thread` this MUST be "mailbox" (keep a clone
/// to send messages to the IO thread).
pub mailbox: Mailbox,
/// A handle to wake up the renderer. This hints to the renderer that that
/// a repaint should happen.
///
/// (The render state itself is created by `Termio::init`; get it with
/// `Termio::renderer_state()`.)
pub renderer_wakeup: Wakeup,
/// The mailbox for renderer messages.
pub renderer_mailbox: Arc<dyn RendererMailbox>,
/// The mailbox for sending the surface messages.
pub surface_mailbox: Arc<dyn SurfaceMailbox>,
}