Files
psyTerm/src/chrome.rs
T
buzzert d7e9be973c 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.
2026-11-17 01:08:35 -08:00

199 lines
6.2 KiB
Rust
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//! psyTerm chrome using the shared Sybil palette from the user's applications.
//!
//! Color sources:
//! - Huayra `src/styles.css`, active `data-theme="sybil"` theme.
//! - Sybil `web/src/index.css`, root color tokens.
//! - Attractor `chrome/browser/resources/attractor/theme.css`, surface tokens.
use std::rc::Rc;
use gpui::{
App, Div, ElementId, MouseButton, SharedString, Stateful, Window, div, prelude::*, px, rgb,
};
use crate::label::middle_label;
pub const APP_BACKGROUND: u32 = 0x06060f;
pub const PANEL_BACKGROUND: u32 = 0x080817;
pub const TERMINAL_BACKGROUND: u32 = 0x080917;
pub const CONTROL_BACKGROUND: u32 = 0x131122;
pub const HOVER_BACKGROUND: u32 = 0x1c1830;
pub const ACTIVE_BACKGROUND: u32 = 0x231c3b;
pub const BORDER: u32 = 0x282145;
pub const TEXT: u32 = 0xf3f1f8;
pub const MUTED: u32 = 0xa29fbc;
pub const ACCENT: u32 = 0x9858f9;
pub const CYAN: u32 = 0x4bdbf1;
// Huayra's Sybil green: hsl(163 72% 45%).
pub const PANE_FOCUS: u32 = 0x20c597;
pub const PANE_MUTED: u32 = 0x527f73;
pub const DANGER: u32 = 0xf26977;
pub const CONTENT_INSET: f32 = 8.;
pub const HEADER_HEIGHT: f32 = 44.;
pub struct ChromeTab {
pub id: u64,
pub label: SharedString,
pub active: bool,
}
/// An app-owned titlebar. Callbacks issue server commands; no tab state lives here.
/// The close callback should detach this GUI, leaving server sessions alive.
pub fn header(
connection: SharedString,
tabs: Vec<ChromeTab>,
on_tab: impl Fn(u64, &mut Window, &mut App) + 'static,
on_new: impl Fn(&mut Window, &mut App) + 'static,
on_close: impl Fn(&mut Window, &mut App) + 'static,
) -> Div {
let on_tab = Rc::new(on_tab);
let mut tab_strip = div()
.flex()
.items_center()
.gap(px(4.))
.flex_1()
.min_w_0()
.h_full()
.overflow_hidden();
for tab in tabs {
let on_tab = on_tab.clone();
let active = tab.active;
let id = tab.id;
tab_strip = tab_strip.child(
div()
.id(ElementId::Name(format!("tab-{id}").into()))
.flex()
.items_center()
.gap(px(7.))
.h(px(29.))
.flex_basis(px(200.))
.flex_shrink()
.min_w_0()
.max_w(px(200.))
.px(px(10.))
.border_1()
.border_color(rgb(if active { BORDER } else { PANEL_BACKGROUND }))
.bg(rgb(if active {
ACTIVE_BACKGROUND
} else {
PANEL_BACKGROUND
}))
.text_color(rgb(if active { TEXT } else { MUTED }))
.text_size(px(11.))
.cursor_pointer()
.hover(|style| style.bg(rgb(HOVER_BACKGROUND)).text_color(rgb(TEXT)))
.on_mouse_down(MouseButton::Left, |_, _, cx| cx.stop_propagation())
.on_click(move |_, window, cx| {
cx.stop_propagation();
on_tab(id, window, cx);
})
.child(
div()
.w(px(3.))
.flex_shrink_0()
.h(px(12.))
.bg(rgb(if active { ACCENT } else { BORDER })),
)
.child(
div()
.flex_1()
.min_w_0()
.h_full()
.overflow_hidden()
.child(middle_label(tab.label)),
),
);
}
div()
.flex()
.flex_col()
.flex_shrink_0()
.h(px(HEADER_HEIGHT))
.w_full()
.bg(rgb(PANEL_BACKGROUND))
.border_b_1()
.border_color(rgb(BORDER))
.font_family(".SystemUIFont")
.text_color(rgb(TEXT))
.child(
div()
.flex()
.items_center()
.gap(px(10.))
.px(px(12.))
.flex_1()
.min_h_0()
.on_mouse_down(MouseButton::Left, |_, window, _| window.start_window_move())
.child(tab_strip)
.child(
div()
.flex()
.items_center()
.flex_shrink_0()
.gap(px(5.))
.max_w(px(170.))
.text_size(px(10.))
.text_color(rgb(MUTED))
.child(div().size(px(4.)).rounded_full().bg(rgb(CYAN)))
.child(div().text_ellipsis().child(connection)),
)
.child(control("new-tab", "+", false, on_new))
.child(control("detach-window", "×", true, on_close)),
)
}
fn control(
id: &'static str,
label: &'static str,
danger: bool,
on_click: impl Fn(&mut Window, &mut App) + 'static,
) -> Stateful<Div> {
div()
.id(id)
.flex()
.items_center()
.justify_center()
.flex_shrink_0()
.size(px(27.))
.text_size(px(18.))
.text_color(rgb(MUTED))
.cursor_pointer()
.hover(move |style| {
style
.bg(rgb(if danger {
CONTROL_BACKGROUND
} else {
HOVER_BACKGROUND
}))
.text_color(rgb(if danger { DANGER } else { TEXT }))
})
.on_mouse_down(MouseButton::Left, |_, _, cx| cx.stop_propagation())
.on_click(move |_, window, cx| {
cx.stop_propagation();
on_click(window, cx);
})
.child(label)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn header_constructs_each_control_without_duplicate_hover_styles() {
// GPUI rejects installing a hover style twice before the first window
// frame. Exercise the complete header, including its danger control.
let _ = header(
"Local".into(),
vec![ChromeTab {
id: 1,
label: "Shell".into(),
active: true,
}],
|_, _, _| {},
|_, _| {},
|_, _| {},
);
}
}