Build server-backed psyTerm with multiplexing and themed UI

Move terminal sessions, tabs, panes, and state into a persistent headless
server with local socket and SSH clients. Launch GUIs through a managed
single-threaded zygote while keeping rendering responsive.

Add animated cursors, themed chrome, teal pane focus outlines, uniform
tabs, and middle-truncated names. Support program/CWD titles, manual
renaming, home-directory abbreviation, and automatic pane/tab removal
when shells exit.

Document the process architecture, controls, and third-party cursor
sources. Validated with 57 tests, strict Clippy, and live Wayland checks.
This commit is contained in:
2026-11-17 01:08:35 -08:00
parent de1d5776b6
commit d7e9be973c
18 changed files with 5257 additions and 410 deletions
+121 -7
View File
@@ -1,15 +1,126 @@
mod chrome;
mod client;
mod colors;
mod cursor;
mod fonts;
mod input;
mod label;
mod launcher;
mod pane_name;
mod protocol;
mod render;
mod server;
mod session;
mod terminal;
use anyhow::{Result, bail};
use gpui::{prelude::*, *};
use std::path::PathBuf;
fn main() -> anyhow::Result<()> {
fn main() -> Result<()> {
env_logger::init();
let (session, events) = session::Session::new()?;
let mut role = "launch";
let mut socket = None;
let mut remote = None;
let mut args = std::env::args().skip(1);
while let Some(arg) = args.next() {
match arg.as_str() {
"--server" => role = "server",
"--zygote" => role = "zygote",
"--gui" => role = "gui",
"--bridge" => role = "bridge",
"--shutdown" => role = "shutdown",
"--list" => role = "list",
"--socket" => {
socket = Some(PathBuf::from(
args.next()
.ok_or_else(|| anyhow::anyhow!("--socket needs a path"))?,
))
}
"--remote" => {
remote = Some(
args.next()
.ok_or_else(|| anyhow::anyhow!("--remote needs an SSH destination"))?,
)
}
"--help" | "-h" => {
println!(
"psyTerm — server-owned terminals with a GPUI front end\n\n psyterm Open a window via the local server's zygote\n psyterm --remote user@host Connect a local GUI to a server over SSH\n psyterm --list List server-owned tabs and panes\n psyterm --shutdown Stop the local server and its shell sessions\n psyterm --socket PATH Use a separate local server\n psyterm --gui Direct GUI launch (diagnostics; bypass zygote)\n psyterm --server Run the server in the foreground\n psyterm --bridge Binary stdin/stdout transport used by SSH\n\nClosing a window detaches; tabs and shells keep running.\nSSH requires key/agent authentication and psyterm in the remote PATH.\nPSYTERM_REMOTE_BIN overrides the remote executable path.\n"
);
return Ok(());
}
_ => bail!("unknown argument: {arg}; see --help"),
}
}
let socket = socket.map(Ok).unwrap_or_else(launcher::default_socket)?;
match role {
"server" => {
let zygote_socket = socket.clone();
let mut zygote: Option<launcher::Zygote> = None;
server::run(&socket, move |remote| {
if zygote.is_none() {
zygote = Some(launcher::Zygote::start(&zygote_socket)?);
}
zygote.as_mut().unwrap().open_window(remote)
})
}
"zygote" => launcher::run_zygote(&socket),
"gui" => {
launcher::ensure_server(&socket)?;
run_gui(socket, remote)
}
"bridge" => client::bridge(&socket),
"shutdown" => {
launcher::control(&socket, protocol::ClientMessage::Shutdown)?;
Ok(())
}
"list" => list_sessions(&socket),
_ => {
launcher::ensure_server(&socket)?;
launcher::control(
&socket,
protocol::ClientMessage::OpenWindow { target: remote },
)?;
Ok(())
}
}
}
fn list_sessions(socket: &std::path::Path) -> Result<()> {
let mut stream = std::os::unix::net::UnixStream::connect(socket)?;
stream.set_read_timeout(Some(std::time::Duration::from_secs(5)))?;
protocol::write_message(
&mut stream,
&protocol::ClientMessage::Hello {
version: protocol::VERSION,
},
)?;
let hello: protocol::ServerMessage = protocol::read_message(&mut stream)?;
println!("{hello:?}");
protocol::write_message(&mut stream, &protocol::ClientMessage::List)?;
loop {
match protocol::read_message(&mut stream)? {
protocol::ServerMessage::Snapshot(snapshot) => {
for tab in snapshot.tabs {
println!("tab {} {} panes {:?}", tab.id, tab.title, tab.panes);
}
break;
}
protocol::ServerMessage::Error(error) => bail!("{error}"),
_ => {}
}
}
Ok(())
}
/// Called directly in a fresh fork of the single-threaded zygote. All GPUI,
/// graphics, font discovery and client I/O initialization happens after fork.
pub(crate) fn run_gui(socket: PathBuf, remote: Option<String>) -> Result<()> {
let (client, updates) = client::Client::connect(&socket, remote.as_deref())?;
let connection: SharedString = remote
.map(|host| format!("SSH · {host}"))
.unwrap_or_else(|| "Local".into())
.into();
Application::new().run(move |cx: &mut App| {
cx.on_window_closed(|cx| {
if cx.windows().is_empty() {
@@ -17,20 +128,23 @@ fn main() -> anyhow::Result<()> {
}
})
.detach();
let bounds = Bounds::centered(None, size(px(960.), px(640.)), cx);
let bounds = Bounds::centered(None, size(px(1000.), px(680.)), cx);
cx.open_window(
WindowOptions {
window_bounds: Some(WindowBounds::Windowed(bounds)),
titlebar: Some(TitlebarOptions {
title: Some("Terminal".into()),
title: Some("psyTerm".into()),
..Default::default()
}),
app_id: Some("dev.buzzert.terminal".into()),
window_decorations: Some(WindowDecorations::Client),
app_id: Some("dev.buzzert.psyterm".into()),
..Default::default()
},
move |window, cx| cx.new(|cx| terminal::TerminalView::new(session, events, window, cx)),
move |window, cx| {
cx.new(|cx| terminal::Workspace::new(client, updates, connection, window, cx))
},
)
.expect("could not open terminal window");
.expect("could not open psyTerm window");
cx.activate(true);
});
Ok(())