Files
ghostty-rs/crates/ghostty-apprt/src/runtime.rs
T
ddidderr 5a5fa7893b feat(apprt): port the core/runtime contract types
Ports ZIG/src/apprt/{action,structs,surface,ipc,runtime}.zig into
ghostty-apprt: the Action enum performed by the core on the app runtime
(all 65 variants with docs), Target<S> generic over the runtime's
surface handle, clipboard/size/scale/selection structs, the core->surface
Message enum with a Mailbox over an AppMailbox trait, and IPC action
types for +new-window.

Owned Strings and Arc<Config> replace Zig's borrowed slices/pointers.
Scrollbar and RendererHealth are local stand-ins until core integration.
The embedded C API and browser runtime are out of scope.

Test Plan:
- cargo test -p ghostty-apprt (16 tests)
2026-10-11 22:25:05 +02:00

62 lines
1.6 KiB
Rust

//! Port of `runtime.zig` (and `none.zig`).
/// Runtime is the runtime to use for Ghostty. All runtimes do not provide
/// equivalent feature sets.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Runtime {
/// Will not produce an executable at all (lib only). Matches `none.zig`:
/// there is no apprt to communicate with, so IPC always returns `false`.
None,
/// GTK4. Rich windowed application. This uses a full GObject-based
/// approach to building the application.
Gtk,
}
impl Runtime {
/// The default runtime for the current target. The Linux and FreeBSD
/// default is GTK because it is a full featured application; otherwise
/// `None`.
#[must_use]
pub fn default_for_target() -> Self {
if cfg!(any(target_os = "linux", target_os = "freebsd")) {
Runtime::Gtk
} else {
Runtime::None
}
}
}
/// `none.zig` `App::performIpc`: always false as there is no apprt to
/// communicate with.
///
/// # Errors
/// Never fails.
pub fn none_perform_ipc(
_target: &crate::ipc::Target,
_action: &crate::ipc::Action,
) -> Result<bool, crate::ipc::Error> {
Ok(false)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn default_runtime_is_gtk_on_linux() {
if cfg!(target_os = "linux") {
assert_eq!(Runtime::default_for_target(), Runtime::Gtk);
}
}
#[test]
fn none_ipc_returns_false() {
let r = none_perform_ipc(
&crate::ipc::Target::Detect,
&crate::ipc::Action::NewWindow(crate::ipc::NewWindow { arguments: None }),
);
assert!(matches!(r, Ok(false)));
}
}