diff --git a/README.md b/README.md index 6e1b707..61e4eb4 100644 --- a/README.md +++ b/README.md @@ -244,9 +244,10 @@ or the server stops. ## Appearance The inset terminal surface and titlebar use the dark Sybil palette shared by -Huayra, Attractor, and Sybil. Tabs retain violet accents; pane headers use teal, -with a matching border around the active pane. The titlebar contains equal-width -tabs and connection/window controls. `src/chrome.rs` records the theme sources. +Huayra, Attractor, and Sybil. Local tabs have a purple accent. SSH tabs have a +teal accent and show the destination hostname beneath their title. Pane headers +use teal, with a matching border around the active pane. +`src/chrome.rs` records the theme sources. Tab changes and new panes slide with Neovide's 150 ms exponential window-motion curve. Outgoing content remains visible during the transition; only the incoming diff --git a/src/chrome.rs b/src/chrome.rs index b83b216..e569113 100644 --- a/src/chrome.rs +++ b/src/chrome.rs @@ -23,7 +23,6 @@ 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; @@ -34,6 +33,7 @@ pub const HEADER_HEIGHT: f32 = 44.; pub struct ChromeTab { pub id: u64, pub label: SharedString, + pub remote: Option, pub active: bool, pub editor: Option>, } @@ -41,7 +41,6 @@ pub struct ChromeTab { /// 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, reserve_traffic_lights: bool, on_tab: impl Fn(u64, &mut Window, &mut App) + 'static, @@ -61,41 +60,68 @@ pub fn header( let on_tab = on_tab.clone(); let active = tab.active; let id = tab.id; - let label = div() + let (accent, selected_bg, hover_bg, selected_border) = if tab.remote.is_some() { + (PANE_FOCUS, 0x102d28, 0x112720, 0x285749) + } else { + (ACCENT, ACTIVE_BACKGROUND, HOVER_BACKGROUND, BORDER) + }; + let mut label = div() .flex_1() .min_w_0() .h_full() .flex() - .items_center() + .flex_col() + .justify_center() .overflow_hidden(); - let label = if let Some(editor) = tab.editor { - label.child(editor) + if let Some(editor) = tab.editor { + label = label.child(editor); } else { - label.child(middle_label(tab.label)) - }; + label = label.child( + div() + .h(px(16.)) + .line_height(px(16.)) + .child(middle_label(tab.label)), + ); + } + if let Some(destination) = tab.remote { + label = label.child( + div() + .h(px(12.)) + .line_height(px(12.)) + .text_size(px(10.)) + .text_color(rgb(PANE_FOCUS)) + .child(middle_label( + remote_hostname(&destination).to_owned().into(), + )), + ); + } tab_strip = tab_strip.child( div() .id(ElementId::Name(format!("tab-{id}").into())) .flex() .items_center() .gap(px(7.)) - .h(px(29.)) + .h(px(38.)) .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 })) + .border_color(rgb(if active { + selected_border + } else { + PANEL_BACKGROUND + })) .bg(rgb(if active { - ACTIVE_BACKGROUND + selected_bg } 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))) + .hover(move |style| style.bg(rgb(hover_bg)).text_color(rgb(TEXT))) .on_mouse_down(MouseButton::Left, |_, _, cx| cx.stop_propagation()) .on_click(move |_, window, cx| { cx.stop_propagation(); @@ -105,8 +131,8 @@ pub fn header( div() .w(px(3.)) .flex_shrink_0() - .h(px(12.)) - .bg(rgb(if active { ACCENT } else { BORDER })), + .h(px(if active { 22. } else { 12. })) + .bg(rgb(accent)), ) .child(label), ); @@ -141,18 +167,6 @@ pub fn header( } }) .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)) .when(!cfg!(target_os = "macos"), |row| { row.child(control("detach-window", "×", true, on_close)) @@ -160,6 +174,22 @@ pub fn header( ) } +/// Keep SSH aliases as entered, omitting user, URI port and IPv6 brackets. +fn remote_hostname(destination: &str) -> &str { + let uri = destination.strip_prefix("ssh://"); + let address = uri.unwrap_or(destination).trim_end_matches('/'); + let host = address.rsplit_once('@').map_or(address, |(_, host)| host); + if let Some((ipv6, _)) = host.strip_prefix('[').and_then(|s| s.split_once(']')) { + return ipv6; + } + if uri.is_some() + && let Some((name, _)) = host.split_once(':') + { + return name; + } + host +} + fn control( id: &'static str, label: &'static str, @@ -197,18 +227,41 @@ fn control( mod tests { use super::*; + #[test] + fn displays_hostnames_for_ssh_destinations() { + for (destination, hostname) in [ + ("workstation", "workstation"), + ("alice@build.lan", "build.lan"), + ("alice@2001:db8::1", "2001:db8::1"), + ("[2001:db8::1]", "2001:db8::1"), + ("ssh://alice@build.lan:2222", "build.lan"), + ("ssh://alice@[2001:db8::1]:2222/", "2001:db8::1"), + ] { + assert_eq!(remote_hostname(destination), hostname); + } + } + #[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, - editor: None, - }], + vec![ + ChromeTab { + id: 1, + label: "Shell".into(), + remote: None, + active: true, + editor: None, + }, + ChromeTab { + id: 2, + label: "Build".into(), + remote: Some("user@work".into()), + active: false, + editor: None, + }, + ], cfg!(target_os = "macos"), |_, _, _| {}, |_, _| {}, diff --git a/src/main.rs b/src/main.rs index 239615c..7273552 100644 --- a/src/main.rs +++ b/src/main.rs @@ -212,10 +212,6 @@ pub(crate) fn run_gui( session: SessionTarget, ) -> Result<()> { let (client, updates) = client::Client::connect(&socket, remote.as_deref(), session)?; - let connection: SharedString = remote - .map(|host| format!("SSH · {host}")) - .unwrap_or_else(|| "Local".into()) - .into(); Application::new().run(move |cx: &mut App| { #[cfg(target_os = "macos")] { @@ -256,9 +252,7 @@ pub(crate) fn run_gui( app_id: Some("dev.buzzert.psyterm".into()), ..Default::default() }, - move |window, cx| { - cx.new(|cx| terminal::Workspace::new(client, updates, connection, window, cx)) - }, + move |window, cx| cx.new(|cx| terminal::Workspace::new(client, updates, window, cx)), ) .expect("could not open psyTerm window"); cx.activate(true); diff --git a/src/terminal.rs b/src/terminal.rs index 7aa9d67..d08f7cc 100644 --- a/src/terminal.rs +++ b/src/terminal.rs @@ -38,7 +38,6 @@ struct TabRename { pub struct Workspace { client: Client, - connection: SharedString, font: TerminalFont, snapshot: Option>, panes: HashMap>, @@ -328,7 +327,6 @@ impl Workspace { pub fn new( client: Client, updates: Updates, - connection: SharedString, window: &mut Window, cx: &mut Context, ) -> Self { @@ -479,7 +477,6 @@ impl Workspace { }); Self { client, - connection, font, snapshot: None, panes: HashMap::new(), @@ -529,6 +526,11 @@ impl Render for Workspace { .map(|tab| chrome::ChromeTab { id: tab.id, label: tab.title.clone().into(), + remote: tab + .remote + .as_deref() + .or(self.client.remote()) + .map(str::to_owned), active: tab.id == s.active_tab, editor: self .tab_rename @@ -542,7 +544,6 @@ impl Render for Workspace { let client = self.client.clone(); let new_client = self.client.clone(); let header = chrome::header( - self.connection.clone(), tabs, cfg!(target_os = "macos") && !window.is_fullscreen(), move |tab, _, _| {