Skip to content

A modern terminal with a built-in multiplexer: close it and your sessions keep running. Run shells and tons of AI agents across your machines, then pick them up from desktop, browser, TUI and more. Written in Rust with no UI framework: interface drawn straight on the GPU. No Electron, GPUI or webview.

gui: rebuild SSH Hosts as Remote Hosts

RoversX829db7e62be6
diff --git a/config/src/keyassignment.rs b/config/src/keyassignment.rs
index 50fc6e59..1f8e8ab8 100644
--- a/config/src/keyassignment.rs
+++ b/config/src/keyassignment.rs
@@ -636,7 +636,11 @@ pub enum KeyAssignment {
ResetTerminal,
OpenUri(String),
OpenSettings,
+ CheckForUpdates,
OpenSshHosts,
+ /// Open the SSH host manager on a blank host form. Distinct from
+ /// `OpenSshHosts`, which toggles the page: this one only ever opens.
+ AddRemoteHost,
ToggleLiveOverview,
ActivateCommandPalette,
/// Switch this window's color scheme. `None` reverts to the configured
diff --git a/thinkterm-tui/src/lib.rs b/thinkterm-tui/src/lib.rs
index 1b2e1118..8db0a8cb 100644
--- a/thinkterm-tui/src/lib.rs
+++ b/thinkterm-tui/src/lib.rs
@@ -859,7 +859,7 @@ fn connection_catalog(
detail: if host.spec.use_mosh {
"Mosh sessions are not mux servers; edit in GUI".into()
} else {
- "Enable ThinkTerm Connect in SSH Hosts".into()
+ "Enable ThinkTerm Connect in Remote Hosts".into()
},
status: ConnectionStatus::Unsupported,
connectable: false,
diff --git a/wezterm-gui/src/commands.rs b/wezterm-gui/src/commands.rs
index 3d381fb8..5ae38a1a 100644
--- a/wezterm-gui/src/commands.rs
+++ b/wezterm-gui/src/commands.rs
@@ -763,14 +763,31 @@ pub fn derive_command_from_key_assignment(action: &KeyAssignment) -> Option<Comm
menubar: &["ThinkTerm"],
icon: Some("cod_settings_gear"),
},
+ CheckForUpdates => CommandDef {
+ brief: "Check for Updates...".into(),
+ doc: "Opens Settings on the Software Update page".into(),
+ keys: vec![],
+ args: &[ArgType::ActiveWindow],
+ menubar: &["ThinkTerm"],
+ icon: Some("md_update"),
+ },
OpenSshHosts => CommandDef {
- brief: "SSH Hosts...".into(),
+ brief: "Remote Hosts...".into(),
doc: "Opens the ThinkTerm SSH host manager".into(),
keys: vec![],
args: &[ArgType::ActiveWindow],
menubar: &["Shell"],
icon: Some("md_server_network"),
},
+ AddRemoteHost => CommandDef {
+ brief: "Add Remote Host...".into(),
+ // Says SSH so that typing it in the palette still finds this.
+ doc: "Opens the ThinkTerm SSH host manager on a blank host".into(),
+ keys: vec![],
+ args: &[ArgType::ActiveWindow],
+ menubar: &["Shell"],
+ icon: Some("md_earth"),
+ },
ToggleLiveOverview => CommandDef {
brief: "Live Overview".into(),
doc: "Shows all live ThinkTerm threads grouped by Space".into(),
@@ -2350,6 +2367,7 @@ fn compute_default_actions() -> Vec<KeyAssignment> {
// These are ordered by their position within the various menus
return vec![
// ----------------- ThinkTerm
+ CheckForUpdates,
ReloadConfiguration,
OpenSettings,
#[cfg(target_os = "macos")]
@@ -2359,6 +2377,7 @@ fn compute_default_actions() -> Vec<KeyAssignment> {
// ----------------- Shell
ToggleLiveOverview,
OpenSshHosts,
+ AddRemoteHost,
ArchiveActiveProject,
ToggleShowArchivedProjects,
SpawnTab(SpawnTabDomain::CurrentPaneDomain),
diff --git a/wezterm-gui/src/ssh_hosts.rs b/wezterm-gui/src/ssh_hosts.rs
index 605b037f..24f8ddc4 100644
--- a/wezterm-gui/src/ssh_hosts.rs
+++ b/wezterm-gui/src/ssh_hosts.rs
@@ -142,7 +142,23 @@ pub fn host_spec(host_id: &str) -> Option<SshHostSpec> {
.map(|entry| entry.spec)
}
+pub fn host_exists(host_id: &str) -> bool {
+ SSH_HOST_STORE
+ .lock()
+ .hosts
+ .iter()
+ .any(|record| record.id == host_id)
+}
+
pub fn try_create_host(spec: SshHostSpec) -> Result<SshHostId> {
+ // Refuse rather than replace. `upsert_host` matches on an id derived from
+ // the endpoint, so saving a *new* host that dials an endpoint some other
+ // host already uses used to overwrite that host's whole record -- its
+ // saved password included -- and leave one card behind wearing the new
+ // name.
+ if host_exists(&host_id_for_host(&spec)) {
+ bail!("a saved host already uses {}", endpoint(&spec));
+ }
let (host_id, spec) = upsert_host(spec)?;
register_ssh_domain(&spec)?;
Ok(host_id)
@@ -183,26 +199,40 @@ fn upsert_host(spec: SshHostSpec) -> Result<(SshHostId, SshHostSpec)> {
Ok((host_id, saved_spec))
}
-pub fn try_update_host(host_id: &str, spec: SshHostSpec) -> Result<bool> {
+/// Save an edited host. Returns the record's id, which is *not* always the
+/// one passed in: the id is derived from the endpoint, so an edit that moves
+/// the host to a different `user@host:port` has to re-key the record or it
+/// stops matching its own spec. `None` means there was no such editable
+/// record.
+pub fn try_update_host(host_id: &str, spec: SshHostSpec) -> Result<Option<SshHostId>> {
if is_system_host_id(host_id) {
- return Ok(false);
+ return Ok(None);
}
let mut store = SSH_HOST_STORE.lock();
+ // The same invariant `try_create_host` enforces, and for the same reason:
+ // one record per endpoint. Editing a host onto an endpoint another record
+ // already owns would leave two records dialing it, both registering a
+ // domain under the single name `ssh_domain_name` derives.
+ let new_id = host_id_for_host(&spec);
+ if new_id != host_id && store.hosts.iter().any(|record| record.id == new_id) {
+ bail!("a saved host already uses {}", endpoint(&spec));
+ }
let Some(record) = store.hosts.iter_mut().find(|record| record.id == host_id) else {
- return Ok(false);
+ return Ok(None);
};
+ record.id = new_id.clone();
record.spec = spec;
save_ssh_host_store(&store)?;
let spec = store
.hosts
.iter()
- .find(|record| record.id == host_id)
+ .find(|record| record.id == new_id)
.map(|record| record.spec.clone());
drop(store);
if let Some(spec) = spec {
register_ssh_domain(&spec)?;
}
- Ok(true)
+ Ok(Some(new_id))
}
pub fn try_remove_host(host_id: &str) -> Result<bool> {
@@ -247,7 +277,7 @@ pub fn is_system_host_id(host_id: &str) -> bool {
/// `user@host` (or `host`, with `:port` when non-default) used for the
/// human-readable domain / workspace identifiers.
-fn endpoint(spec: &SshHostSpec) -> String {
+pub(crate) fn endpoint(spec: &SshHostSpec) -> String {
let host = match spec.port {
Some(port) if port != 22 => format!("{}:{port}", spec.host),
_ => spec.host.clone(),
@@ -694,7 +724,11 @@ fn fnv1a(input: &str) -> u64 {
hash
}
-fn host_id_for_host(spec: &SshHostSpec) -> SshHostId {
+/// The record id for a host, derived from `user@host:port` alone -- so two
+/// hosts that dial the same endpoint are the same record no matter what they
+/// are named. Both save paths lean on that: see `try_create_host` and
+/// `try_update_host`.
+pub fn host_id_for_host(spec: &SshHostSpec) -> SshHostId {
let key = format!(
"ssh:{}@{}:{}",
spec.username.as_deref().unwrap_or(""),
diff --git a/wezterm-gui/src/termwindow/content_view.rs b/wezterm-gui/src/termwindow/content_view.rs
index cd316841..cc8ce987 100644
--- a/wezterm-gui/src/termwindow/content_view.rs
+++ b/wezterm-gui/src/termwindow/content_view.rs
@@ -374,6 +374,17 @@ pub(crate) enum ContentViewResponse {
Run(Box<dyn FnOnce(&mut TermWindow)>),
}
+/// One entry of the Remote Hosts page's card menu. Lives here rather than in
+/// the page because the window is what dispatches it: a native menu reports
+/// back to the window, not to the view that asked for it.
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+pub(crate) enum RemoteHostCommand {
+ Connect,
+ Edit,
+ Duplicate,
+ Delete,
+}
+
pub(crate) trait ContentView {
/// Title shown on the synthetic tab.
fn title(&self) -> String;
@@ -432,6 +443,22 @@ pub(crate) trait ContentView {
/// Default is a no-op; only the remote-thread view reacts.
fn on_remote_connect_phase(&mut self, _phase: RemoteConnectPhase) {}
+ /// Send an already-open hosts page straight to its blank host form.
+ /// The menu entry that leads here is worded as an action, so landing on
+ /// the list would leave the user a click short of what they asked for.
+ /// Default is a no-op; only the SSH hosts view reacts.
+ fn begin_new_remote_host(&mut self) {}
+
+ /// Run one entry of that page's card menu. Default is a no-op; only the
+ /// remote hosts page reacts.
+ fn run_remote_host_command(
+ &mut self,
+ _host_id: &str,
+ _command: RemoteHostCommand,
+ ) -> ContentViewResponse {
+ ContentViewResponse::Ignored
+ }
+
/// Gate a re-authorization round trip for the project-root page and
/// report whether it may start. Default is a no-op refusal; only the
/// project-root view participates.
diff --git a/wezterm-gui/src/termwindow/mod.rs b/wezterm-gui/src/termwindow/mod.rs
index 10b7e18e..f962ba88 100644
--- a/wezterm-gui/src/termwindow/mod.rs
+++ b/wezterm-gui/src/termwindow/mod.rs
@@ -491,6 +491,14 @@ pub(crate) enum NoteEditorCommand {
#[derive(Clone, Debug)]
pub(crate) enum ContextMenuApplicationAction {
Note(NoteEditorCommand),
+ /// One entry of the Remote Hosts page's card menu, carrying the host it
+ /// was raised on. An owned id rather than a list index: the page's
+ /// filtered list can change between building the menu and choosing from
+ /// it, and an index would then point at a different machine.
+ RemoteHost {
+ host_id: String,
+ command: crate::termwindow::content_view::RemoteHostCommand,
+ },
SetFrontendAccessMode(codec::FrontendAccessMode),
/// Notification bell entry: jump to a thread, switching Space first when
/// it lives elsewhere, and acknowledge its unseen work.
@@ -6435,6 +6443,98 @@ impl TermWindow {
}
}
+ /// The card menu for the Remote Hosts page. Built here because a menu
+ /// belongs to the window: the page has no window handle, and a native
+ /// menu reports its choice back to the window anyway.
+ pub(crate) fn show_remote_host_menu(
+ &mut self,
+ host_id: String,
+ label: String,
+ editable: bool,
+ x: f32,
+ y: f32,
+ ) {
+ use crate::termwindow::content_view::RemoteHostCommand;
+ let Some(window) = self.window.as_ref().cloned() else {
+ return;
+ };
+ self.begin_context_menu_application_actions();
+ let mut items = vec![self.context_menu_application_item_with_icon(
+ crate::i18n::tr("ssh-menu-connect"),
+ ContextMenuIcon::Terminal,
+ ContextMenuApplicationAction::RemoteHost {
+ host_id: host_id.clone(),
+ command: RemoteHostCommand::Connect,
+ },
+ true,
+ )];
+ if editable {
+ items.push(ContextMenuItem::Separator);
+ items.push(self.context_menu_application_item_with_icon(
+ crate::i18n::tr("ssh-menu-edit"),
+ ContextMenuIcon::Edit,
+ ContextMenuApplicationAction::RemoteHost {
+ host_id: host_id.clone(),
+ command: RemoteHostCommand::Edit,
+ },
+ true,
+ ));
+ items.push(self.context_menu_application_item_with_icon(
+ crate::i18n::tr("ssh-menu-duplicate"),
+ ContextMenuIcon::Copy,
+ ContextMenuApplicationAction::RemoteHost {
+ host_id: host_id.clone(),
+ command: RemoteHostCommand::Duplicate,
+ },
+ true,
+ ));
+ items.push(ContextMenuItem::Separator);
+ // Deleting a host takes its threads and its mirrored Spaces with
+ // it and cannot be undone, so it asks first.
+ let confirm = self.context_menu_application_item_with_icon(
+ crate::i18n::tr("ssh-menu-delete-confirm"),
+ ContextMenuIcon::Delete,
+ ContextMenuApplicationAction::RemoteHost {
+ host_id,
+ command: RemoteHostCommand::Delete,
+ },
+ true,
+ );
+ let mut args = fluent_bundle::FluentArgs::new();
+ args.set("name", label);
+ items.push(ContextMenuItem::submenu_with_icon(
+ crate::i18n::tr_args("ssh-menu-delete-named", &args),
+ ContextMenuIcon::Delete,
+ vec![
+ ContextMenuItem::section_header(crate::i18n::tr("ssh-menu-delete-explain")),
+ confirm,
+ ],
+ ));
+ }
+ self.show_term_context_menu(&window, euclid::point2(x as isize, y as isize), items);
+ }
+
+ /// Open the SSH hosts page on a blank host form. Unlike
+ /// `toggle_ssh_hosts_view` this never closes an open page: it is reached
+ /// from a menu entry worded as an action, and an action that sometimes
+ /// closes the page instead is not one.
+ pub(crate) fn open_ssh_hosts_view_new_host(&mut self) {
+ let key = crate::termwindow::ssh_hosts_view::SSH_HOSTS_CONTENT_VIEW_KEY;
+ match self.content_view_id_for_key(key) {
+ Some(id) => {
+ self.activate_content_view(id);
+ if let Some(view) = self.content_view_mut_by_id(id) {
+ view.begin_new_remote_host();
+ }
+ }
+ None => {
+ self.open_content_view(Box::new(
+ crate::termwindow::ssh_hosts_view::SshHostsView::new_host(),
+ ));
+ }
+ }
+ }
+
/// Toggle the SSH hosts content view (sidebar button / OpenSshHosts).
pub(crate) fn toggle_ssh_hosts_view(&mut self) {
let key = crate::termwindow::ssh_hosts_view::SSH_HOSTS_CONTENT_VIEW_KEY;
@@ -8941,9 +9041,15 @@ impl TermWindow {
OpenSettings => {
crate::settings_window::show();
}
+ CheckForUpdates => {
+ crate::settings_window::show_update_page();
+ }
OpenSshHosts => {
self.toggle_ssh_hosts_view();
}
+ AddRemoteHost => {
+ self.open_ssh_hosts_view_new_host();
+ }
ToggleLiveOverview => {
self.toggle_live_overview_view();
}
diff --git a/wezterm-gui/src/termwindow/mouseevent.rs b/wezterm-gui/src/termwindow/mouseevent.rs
index 01e873a2..6ccb22ba 100644
--- a/wezterm-gui/src/termwindow/mouseevent.rs
+++ b/wezterm-gui/src/termwindow/mouseevent.rs
@@ -531,7 +531,11 @@ impl super::TermWindow {
} else {
configured_button_size
};
- let action_button_count = if self.right_sidebar_width() > 0 && cfg!(target_os = "macos") {
+ let action_button_count = if !self.right_sidebar_has_panels() {
+ // Every sidebar panel is off, so fancy_tab_bar paints no toggle;
+ // reserving its width anyway just shortens the tab strip.
+ 1
+ } else if self.right_sidebar_width() > 0 && cfg!(target_os = "macos") {
1
} else {
2
@@ -5524,6 +5528,17 @@ impl super::TermWindow {
));
}
+ // The servers listed above are what this adds another of. Kept out of
+ // the Space block below because a remote host is a connection, not a
+ // Space: one host can carry several. It stays visible with no servers
+ // configured at all -- then it is the only path to the first one.
+ items.push(ContextMenuItem::Separator);
+ items.push(ContextMenuItem::item_with_icon(
+ crate::i18n::tr("menu-add-remote-host"),
+ ContextMenuIcon::Network,
+ KeyAssignment::AddRemoteHost,
+ ));
+
items.push(ContextMenuItem::Separator);
items.push(ContextMenuItem::item_with_icon(
crate::i18n::tr("menu-new-space"),
@@ -6090,6 +6105,16 @@ impl super::TermWindow {
// <name>` — rather than opening a direct-ssh remote thread.
if spec.multiplexing && !spec.use_mosh {
let name = spec.label.clone();
+ // These hosts used to skip OS detection entirely: the branch
+ // returned before anything read `detect_os`, and both detection
+ // call sites downcast to `RemoteSshDomain`, which a mux client
+ // domain is not. There is no ssh session here to borrow for an
+ // `exec` either -- it is buried in the client's transport -- so
+ // the server reports its own distro in the version handshake and
+ // this just reads what it said.
+ let detect = spec.detect_os && spec.detected_distro.is_none();
+ let detect_host_id = host_id.clone();
+ let detect_window = self.window.as_ref().cloned();
promise::spawn::spawn(async move {
let domain = match Mux::get().get_domain_by_name(&name) {
Some(domain) => domain,
@@ -6101,8 +6126,23 @@ impl super::TermWindow {
}
},
};
+ let attached = Arc::clone(&domain);
if let Err(err) = crate::connect_domain_into_space(None, domain).await {
log::error!("connect {name}: {err:#}");
+ return;
+ }
+ if detect {
+ if let Some(distro) = attached
+ .as_ref()
+ .downcast_ref::<wezterm_client::domain::ClientDomain>()
+ .and_then(|client| client.remote_os_release())
+ {
+ if crate::ssh_hosts::set_host_distro(&detect_host_id, &distro) {
+ if let Some(window) = detect_window.as_ref() {
+ window.invalidate();
+ }
+ }
+ }
}
})
.detach();
diff --git a/wezterm-gui/src/termwindow/ssh_hosts_view.rs b/wezterm-gui/src/termwindow/ssh_hosts_view.rs
index b82176e9..035d7c96 100644
--- a/wezterm-gui/src/termwindow/ssh_hosts_view.rs
+++ b/wezterm-gui/src/termwindow/ssh_hosts_view.rs
@@ -1,21 +1,26 @@
-//! In-window SSH hosts manager: a full-content-area "page" (left host list +
-//! right edit form) that replaces the terminal area when toggled from the
-//! sidebar `link-2` button. Draws with the shared `ui::draw`/`ui::widgets`
+//! In-window remote hosts manager: a full-content-area "page" (left host list
+//! + right edit form) that replaces the terminal area when toggled from the
+//! sidebar globe button. Named "Remote Hosts" in the UI because it also
+//! covers Mosh and ThinkTerm Connect; the code stays `ssh_hosts` since every
+//! mode still dials out over SSH. Draws with the shared `ui::draw`/`ui::widgets`
//! infrastructure. The view owns its state + hit-testing and exposes a tiny
//! [`SshViewOutcome`] so `TermWindow` integration stays minimal.
-use crate::quad::TripleLayerQuadAllocator;
+use crate::quad::{HeapQuadAllocator, QuadClipRect, TripleLayerQuadAllocator};
use crate::ssh_hosts::{self, SshHostEntry, SshHostSource, SshHostSpec};
-use crate::termwindow::content_view::{ContentView, ContentViewResponse};
+use crate::termwindow::content_view::{ContentView, ContentViewResponse, RemoteHostCommand};
use crate::termwindow::ui::icons::{distro_to_icon, SvgIcon};
use crate::termwindow::TermWindow;
use crate::ui::anim::Easing;
use crate::ui::{
- char_index_for_x, contains, draw_button, draw_icon_button, draw_scrollbar, draw_text_input,
- draw_toggle, rect, text_width_to_char, wheel_delta_pixels, ButtonSpec, ControlState,
- DrawContext, EditModifiers, InputCaret, InteractionState, ScrollState, TextInputSpec,
+ card_grid, card_is_warm, card_rect, char_index_for_x, contains, draw_button,
+ draw_button_on_layer, draw_icon_button, draw_scrollbar, draw_text_input,
+ draw_text_input_on_layer, draw_toggle, rect, row_visible, shared_grid_columns,
+ wheel_delta_pixels, ButtonSpec, ButtonVariant, CardGrid, ControlState, DrawContext,
+ EditModifiers, InputCaret, InteractionState, RowAlign, ScrollState, TextInputSpec,
TextInputState, UiContext, UiPalette, UiTokens, WidgetKind,
};
+use crate::utilsprites::RenderMetrics;
use crate::workspace_threads;
use fluent_bundle::FluentArgs;
use std::rc::Rc;
@@ -36,18 +41,7 @@ const FIELD_WORKSPACE: usize = 6;
const FIELD_MOSH_SERVER: usize = 7;
const BASE_FIELD_COUNT: usize = 7;
const FIELD_COUNT: usize = 8;
-const FIELD_LABEL_KEYS: [&str; BASE_FIELD_COUNT] = [
- "ssh-field-name",
- "ssh-field-host",
- "ssh-field-port",
- "ssh-field-user",
- "ssh-field-password",
- "ssh-field-identity",
- "ssh-field-workspace",
-];
-
-/// Heading emitted before the field at the given index, so the form reads as
-/// Connection / Authentication / Session rather than one flat column.
+
/// Where focus lands when the Advanced section is collapsed. Rows inside it
/// stop being drawn, so a focus still pointing at one would silently edit an
/// invisible field; anything else keeps its place.
@@ -93,53 +87,73 @@ fn text_input_with(text: String) -> TextInputState {
input
}
-const FIELD_GROUP_HEADING_KEYS: [(usize, &str); 3] = [
- (FIELD_NAME, "ssh-group-connection"),
- (FIELD_PASSWORD, "ssh-group-authentication"),
- (FIELD_WORKSPACE, "ssh-group-session"),
-];
-
fn ssh_error(id: &'static str, error: impl Into<String>) -> String {
let mut args = FluentArgs::new();
args.set("error", error.into());
crate::i18n::tr_args(id, &args)
}
-const PAD: f32 = 20.0;
-const LEFT_DEFAULT_W: f32 = 500.0;
-const LEFT_MIN_W: f32 = 360.0;
-const LEFT_MAX_W: f32 = 680.0;
-const RIGHT_MIN_W: f32 = 360.0;
-const SPLIT_HANDLE_W: f32 = 14.0;
-const ROW_MIN_H: f32 = 92.0;
-const ROW_GAP: f32 = 14.0;
-const GROUP_ROW_H: f32 = 44.0;
-const INPUT_H: f32 = 44.0;
-const BTN_H: f32 = 42.0;
-const HOST_ROW_RADIUS: f32 = 14.0;
-const HOST_ACTION_RIGHT_PAD: f32 = 14.0;
-const HOST_ACTION_GAP: f32 = 8.0;
-const HOST_ACTION_BTN: f32 = 32.0;
+const PAD: f32 = 24.0;
+const TOOLBAR_H: f32 = 54.0;
+const TOOLBAR_GAP: f32 = 20.0;
+/// The inspector never grows with the window. A form wider than this is
+/// harder to read, not easier, so every extra pixel goes to the grid --
+/// which is the half that actually has more to show.
+const INSPECTOR_W: f32 = 480.0;
+const INSPECTOR_GAP: f32 = 20.0;
+const CARD_MIN_W: f32 = 340.0;
+/// How wide a card may grow before the grid adds another column. Generous
+/// on purpose: cap it too low and a full row ends up narrower than the page,
+/// which is how a grid ends up with a margin it never asked for.
+const CARD_MAX_W: f32 = 560.0;
+const CARD_GAP: f32 = 18.0;
+const CARD_RADIUS: f32 = 36.0;
+const CARD_PAD: f32 = 22.0;
+/// Past five across the cards are too narrow to hold a machine's name and
+/// its endpoint without truncating one of them, which is the only reason to
+/// have a card at all.
+const MAX_CARD_COLUMNS: usize = 5;
+const GROUP_HEADER_H: f32 = 38.0;
+/// Breathing room between a group's caption and its first row of cards.
+const GROUP_TITLE_GAP: f32 = 10.0;
+const GROUP_GAP: f32 = 22.0;
+const INPUT_H: f32 = 54.0;
+const BTN_H: f32 = 54.0;
const LIST_FADE_HEIGHT: f32 = 32.0;
+/// The search field stays this wide however wide the window gets: a text box
+/// spanning a 5K display is a worse target, not a better one.
+const SEARCH_W: f32 = 360.0;
+/// Gap between the stacked cards of the inspector.
+const INSPECTOR_CARD_GAP: f32 = 16.0;
+/// Gap between a field label and its input, and between two fields.
+const LABEL_GAP: f32 = 7.0;
+const FIELD_GAP: f32 = 18.0;
+/// A second click in the same spot within this long connects instead of
+/// re-selecting. Views never receive the window's click counting, so the
+/// page has to notice a double click itself.
+const DOUBLE_CLICK: std::time::Duration = std::time::Duration::from_millis(450);
+/// How far the pointer may drift between the two clicks of a double click.
+const DOUBLE_CLICK_SLOP: f32 = 6.0;
/// Clickable targets inside the view. `usize` payloads index into the current
/// filtered host list, so the action type stays `Copy` (needed by `UiContext`).
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
enum SshViewAction {
Search,
- Connect(usize),
- Edit(usize),
- Delete(usize),
+ /// A host card: first click selects it, a second one connects.
+ Card(usize),
New,
+ /// Connect to the host the inspector is showing.
+ Connect,
FocusField(usize),
ToggleDetect,
ToggleMosh,
ToggleMux,
+ RevealPassword,
Save,
SaveAndConnect,
Cancel,
ToggleSystemHosts,
- ResizeLeftPane,
ToggleAdvanced,
FocusOptionKey(usize),
FocusOptionValue(usize),
@@ -181,15 +195,23 @@ pub(crate) struct SshHostsView {
filtered: Vec<SshHostEntry>,
system_host_count: usize,
system_hosts_collapsed: bool,
- /// Split position in design pixels; painted via ctx.px.
- left_width: f32,
- dragging_left_pane: bool,
- last_area_x: f32,
- last_area_w: f32,
/// ui scale captured at paint time so mouse handlers (no DrawContext)
/// can convert pointer pixels back into design pixels.
last_ui_scale: f32,
+ /// Scrollable region holding the host grid.
list_area: RectF,
+ /// Rect of each painted card, in the same order as `filtered`, so a
+ /// right-click can name the host under the pointer.
+ card_rects: Vec<(usize, RectF)>,
+ /// Reveal the password field's characters. Per-session and per-form: it
+ /// resets whenever another host is opened.
+ password_visible: bool,
+ /// The host, pointer position and time of the last card click, for the
+ /// page's own double-click detection.
+ last_click: Option<(String, f32, f32, std::time::Instant)>,
+ /// Whether `selected` reflects a real choice. Without it the page would
+ /// open with the first card already highlighted.
+ selection_active: bool,
/// Absolute x of a click that should become a caret position. Mouse
/// handlers have no `DrawContext`, so glyph measurement is deferred to the
/// next paint, which knows the font and the field's text origin.
@@ -217,12 +239,12 @@ impl SshHostsView {
filtered: Vec::new(),
system_host_count: 0,
system_hosts_collapsed: true,
- left_width: LEFT_DEFAULT_W,
- dragging_left_pane: false,
- last_area_x: 0.0,
- last_area_w: 0.0,
last_ui_scale: 1.0,
list_area: rect(0.0, 0.0, 0.0, 0.0),
+ card_rects: Vec::new(),
+ password_visible: false,
+ last_click: None,
+ selection_active: false,
pending_caret_click: None,
form_scroll: ScrollState::new(),
form_content_h: 0.0,
@@ -235,6 +257,14 @@ impl SshHostsView {
view
}
+ /// A page that opens straight on a blank host form, for the "Add Remote
+ /// Host" entry point.
+ pub(crate) fn new_host() -> Self {
+ let mut view = Self::new();
+ view.open_new_form();
+ view
+ }
+
fn refresh(&mut self) {
let needle = self.search.text().trim().to_ascii_lowercase();
let show_system_hosts = !self.system_hosts_collapsed || !needle.is_empty();
@@ -298,6 +328,9 @@ impl SshHostsView {
let Some(spec) = ssh_hosts::host_spec(project_id) else {
return;
};
+ // Revealing a password is a decision about one host. Carrying it into
+ // the next one would put a stored password on screen unasked.
+ self.password_visible = false;
let mut fields: [String; FIELD_COUNT] = Default::default();
fields[FIELD_NAME] = spec.label.clone();
fields[FIELD_HOST] = spec.host.clone();
@@ -349,6 +382,8 @@ impl SshHostsView {
fn close_form(&mut self) {
self.form = None;
self.focus = Focus::Search;
+ // Revealing a password is a decision about one host, not a mode.
+ self.password_visible = false;
self.reset_form_scroll();
}
@@ -436,10 +471,27 @@ impl SshHostsView {
mosh_server_command.to_string()
};
+ // One record per endpoint, checked before either path. A record is
+ // keyed by its endpoint, so `editing` already equals this id when an
+ // edit leaves the endpoint alone -- which is the one case that is not
+ // a collision. Saving is what reports it; `ssh_hosts` refuses the
+ // same thing again underneath, without the localized wording.
+ let endpoint_id = ssh_hosts::host_id_for_host(&spec);
+ if form.editing.as_deref() != Some(endpoint_id.as_str())
+ && ssh_hosts::host_exists(&endpoint_id)
+ {
+ let mut args = FluentArgs::new();
+ args.set("endpoint", ssh_hosts::endpoint(&spec));
+ form.error = Some(crate::i18n::tr_args("ssh-error-duplicate", &args));
+ return None;
+ }
+
let project_id = match &form.editing {
Some(id) => match ssh_hosts::try_update_host(id, spec) {
- Ok(true) => id.clone(),
- Ok(false) => {
+ // Not `id`: moving the host to another endpoint re-keys the
+ // record, and the caller selects what comes back.
+ Ok(Some(saved_id)) => saved_id,
+ Ok(None) => {
form.error = Some(crate::i18n::tr("ssh-error-host-missing"));
return None;
}
@@ -486,14 +538,6 @@ impl SshHostsView {
}
}
WMEK::Move => {
- if self.dragging_left_pane {
- let scale = self.last_ui_scale.max(0.01);
- self.left_width = Self::clamp_left_width(
- (x - self.last_area_x) / scale,
- self.last_area_w / scale,
- );
- return ContentViewResponse::Redraw;
- }
if self.interaction.hovered != hit {
self.interaction.hovered = hit;
ContentViewResponse::Redraw
@@ -503,20 +547,32 @@ impl SshHostsView {
}
WMEK::Press(MousePress::Left) => {
self.interaction.pressed = hit;
- if hit == Some(SshViewAction::ResizeLeftPane) {
- self.dragging_left_pane = true;
- }
ContentViewResponse::Redraw
}
WMEK::Release(MousePress::Left) => {
- if self.dragging_left_pane {
- self.dragging_left_pane = false;
- self.interaction.pressed = None;
- return ContentViewResponse::Redraw;
- }
let pressed = self.interaction.pressed.take();
+ // A second click in the same spot connects to the host the
+ // first one selected. Keyed on the pointer rather than on the
+ // card under it: selecting a host opens the inspector, which
+ // takes its width off the grid and reflows it, so by the
+ // second click this position can belong to another card
+ // entirely -- or to no card at all.
+ if let Some((host_id, click_x, click_y, at)) = self.last_click.take() {
+ if at.elapsed() < DOUBLE_CLICK
+ && (x - click_x).abs() <= self.last_ui_scale * DOUBLE_CLICK_SLOP
+ && (y - click_y).abs() <= self.last_ui_scale * DOUBLE_CLICK_SLOP
+ {
+ return open_thread_response(host_id);
+ }
+ }
if let (Some(a), Some(b)) = (hit, pressed) {
if a == b {
+ if let SshViewAction::Card(index) = a {
+ if let Some(entry) = self.filtered.get(index) {
+ self.last_click =
+ Some((entry.id.clone(), x, y, std::time::Instant::now()));
+ }
+ }
self.pending_caret_click = match a {
SshViewAction::Search => Some((Focus::Search, x)),
SshViewAction::FocusField(n) => Some((Focus::Field(n), x)),
@@ -529,6 +585,13 @@ impl SshHostsView {
}
ContentViewResponse::Redraw
}
+ WMEK::Press(MousePress::Right) => {
+ // A right press opens the menu. Clear any pending left-button
+ // bookkeeping first: the menu runs its own event loop and the
+ // matching release never comes back to us.
+ self.interaction.pressed = None;
+ self.host_context_menu(x, y)
+ }
_ => ContentViewResponse::Ignored,
}
}
@@ -591,63 +654,23 @@ impl SshHostsView {
self.open_new_form();
ContentViewResponse::Redraw
}
- SshViewAction::Edit(i) => {
- if let Some(entry) = self.filtered.get(i) {
- let id = entry.id.clone();
- if entry.source == SshHostSource::ThinkTerm {
- self.open_edit_form(&id);
- }
- }
+ SshViewAction::Card(index) => {
+ // The double click that connects is resolved in the mouse
+ // handler, which is the only place that knows where the
+ // pointer was.
+ self.select_host(index);
ContentViewResponse::Redraw
}
- SshViewAction::Delete(i) => {
- let Some(entry) = self
- .filtered
- .get(i)
- .filter(|entry| entry.source == SshHostSource::ThinkTerm)
- else {
- return ContentViewResponse::Redraw;
- };
- let id = entry.id.clone();
- // Read what this host brought in while the record naming it is
- // still here. A ThinkTerm Connect host mirrors whole Spaces
- // from its mux server, and those are keyed by domain name, not
- // by host id — so `remove_project` below, which matches the
- // host id, never sees them. Left behind they are unreachable:
- // nothing resolves the domain to connect, and every rename or
- // delete is refused because it has to go through a server this
- // device can no longer name.
- let host_domains = ssh_hosts::domain_names_for_host(&entry.spec);
- let orphaned_spaces = workspace_threads::space_ids_for_domains(&host_domains);
-
- if let Err(err) = ssh_hosts::try_remove_host(&id) {
- log::error!("failed to delete SSH host {id}: {err:#}");
- self.refresh();
- return ContentViewResponse::Redraw;
+ SshViewAction::Connect => {
+ let id = self.form.as_ref().and_then(|form| form.editing.clone());
+ match id {
+ Some(id) => open_thread_response(id),
+ None => ContentViewResponse::Redraw,
}
- let _ = workspace_threads::remove_project(&id);
- // References into this host's mux Spaces would otherwise
- // linger as permanent grey rows: with the host record gone,
- // nothing can ever resolve them again.
- workspace_threads::purge_thread_refs_for_machines(&host_domains);
- self.refresh();
-
- if orphaned_spaces.is_empty() {
- return ContentViewResponse::Redraw;
- }
- // Through the window, because one of them may be the Space
- // this very window is showing; that path moves it off first.
- // Local removal: the server keeps its Spaces, so re-adding the
- // host brings them back.
- ContentViewResponse::Run(Box::new(move |term_window| {
- for space_id in orphaned_spaces {
- term_window.start_delete_space(
- &space_id,
- workspace_threads::SpaceRemoval::Local,
- false,
- );
- }
- }))
+ }
+ SshViewAction::RevealPassword => {
+ self.password_visible = !self.password_visible;
+ ContentViewResponse::Redraw
}
SshViewAction::FocusField(n) => {
let count = self
@@ -708,17 +731,188 @@ impl SshHostsView {
}
SshViewAction::ToggleSystemHosts => {
self.system_hosts_collapsed = !self.system_hosts_collapsed;
+ // The list is about to be re-filtered under the highlight, and
+ // `selected` is an index into it. Rather than let the ring --
+ // and Enter -- land on whichever host inherits that slot, drop
+ // the selection.
+ self.selection_active = false;
self.refresh();
ContentViewResponse::Redraw
}
- SshViewAction::ResizeLeftPane => ContentViewResponse::Redraw,
- SshViewAction::Connect(i) => match self.filtered.get(i) {
- Some(entry) => open_thread_response(entry.id.clone()),
- None => ContentViewResponse::Redraw,
- },
}
}
+ /// Show a host in the inspector. A host that came from `~/.ssh/config`
+ /// has no record of ours to edit, so selecting one only highlights it.
+ fn select_host(&mut self, index: usize) {
+ self.selected = index;
+ self.selection_active = true;
+ let Some(entry) = self.filtered.get(index) else {
+ return;
+ };
+ let id = entry.id.clone();
+ // Re-selecting the host already open would rebuild its form from disk
+ // and throw away everything typed into it -- including on the first
+ // click of a double click, which is a gesture, not an edit.
+ if self.form.as_ref().and_then(|form| form.editing.as_deref()) == Some(id.as_str()) {
+ return;
+ }
+ match entry.source {
+ SshHostSource::ThinkTerm => self.open_edit_form(&id),
+ SshHostSource::System => self.close_form(),
+ }
+ }
+
+ /// Delete a host and everything that only existed because of it.
+ fn delete_host(&mut self, host_id: &str) -> ContentViewResponse {
+ let Some(entry) = self
+ .filtered
+ .iter()
+ .find(|entry| entry.id == host_id)
+ .filter(|entry| entry.source == SshHostSource::ThinkTerm)
+ else {
+ return ContentViewResponse::Redraw;
+ };
+ // Read what this host brought in while the record naming it is still
+ // here. A ThinkTerm Connect host mirrors whole Spaces from its mux
+ // server, and those are keyed by domain name, not by host id -- so
+ // `remove_project` below, which matches the host id, never sees them.
+ // Left behind they are unreachable: nothing resolves the domain to
+ // connect, and every rename or delete is refused because it has to go
+ // through a server this device can no longer name.
+ let host_domains = ssh_hosts::domain_names_for_host(&entry.spec);
+ let orphaned_spaces = workspace_threads::space_ids_for_domains(&host_domains);
+
+ if let Err(err) = ssh_hosts::try_remove_host(host_id) {
+ log::error!("failed to delete SSH host {host_id}: {err:#}");
+ self.refresh();
+ return ContentViewResponse::Redraw;
+ }
+ let _ = workspace_threads::remove_project(host_id);
+ // References into this host's mux Spaces would otherwise linger as
+ // permanent grey rows: with the host record gone, nothing can ever
+ // resolve them again.
+ workspace_threads::purge_thread_refs_for_machines(&host_domains);
+ if self.form.as_ref().and_then(|form| form.editing.as_deref()) == Some(host_id) {
+ self.close_form();
+ }
+ self.selection_active = false;
+ self.refresh();
+
+ if orphaned_spaces.is_empty() {
+ return ContentViewResponse::Redraw;
+ }
+ // Through the window, because one of them may be the Space this very
+ // window is showing; that path moves it off first. Local removal: the
+ // server keeps its Spaces, so re-adding the host brings them back.
+ ContentViewResponse::Run(Box::new(move |term_window| {
+ for space_id in orphaned_spaces {
+ term_window.start_delete_space(
+ &space_id,
+ workspace_threads::SpaceRemoval::Local,
+ false,
+ );
+ }
+ }))
+ }
+
+ /// Duplicate a host under a new name, ready to be edited.
+ fn duplicate_host(&mut self, host_id: &str) -> ContentViewResponse {
+ let Some(spec) = self
+ .filtered
+ .iter()
+ .find(|entry| entry.id == host_id)
+ .map(|entry| entry.spec.clone())
+ else {
+ return ContentViewResponse::Redraw;
+ };
+ self.open_new_form();
+ if let Some(form) = self.form.as_mut() {
+ form.fields[FIELD_NAME].set_text_end(format!("{} copy", spec.label));
+ // Everything but the hostname. A record is keyed by its endpoint,
+ // so a duplicate carrying the original's host could never be
+ // saved -- it would collide with the host it was copied from.
+ // `open_new_form` has already put the caret in this field.
+ if let Some(port) = spec.port {
+ form.fields[FIELD_PORT] = text_input_with(port.to_string());
+ }
+ if let Some(user) = spec.username.clone() {
+ form.fields[FIELD_USER].set_text_end(user);
+ }
+ if let Some(identity) = spec.identity_file.clone() {
+ form.fields[FIELD_IDENTITY].set_text_end(identity);
+ }
+ if let Some(workspace) = spec.default_workspace.clone() {
+ form.fields[FIELD_WORKSPACE].set_text_end(workspace);
+ }
+ if let Some(password) = spec.password.as_deref().map(crate::secret::reveal) {
+ form.fields[FIELD_PASSWORD] = text_input_with(password);
+ }
+ form.fields[FIELD_MOSH_SERVER] = text_input_with(spec.mosh_server_command.clone());
+ form.detect_os = spec.detect_os;
+ form.use_mosh = spec.use_mosh;
+ form.multiplexing = spec.multiplexing;
+ form.options = spec
+ .ssh_options
+ .iter()
+ .map(|(key, value)| (text_input_with(key.clone()), text_input_with(value.clone())))
+ .collect();
+ form.advanced_open = !form.options.is_empty();
+ }
+ ContentViewResponse::Redraw
+ }
+
+ /// Run one of the card menu's entries. Reached from the window, which is
+ /// where the native menu reports back to.
+ pub(crate) fn run_host_command(
+ &mut self,
+ host_id: &str,
+ command: RemoteHostCommand,
+ ) -> ContentViewResponse {
+ match command {
+ RemoteHostCommand::Connect => open_thread_response(host_id.to_string()),
+ RemoteHostCommand::Edit => {
+ if let Some(index) = self.filtered.iter().position(|e| e.id == host_id) {
+ self.select_host(index);
+ }
+ ContentViewResponse::Redraw
+ }
+ RemoteHostCommand::Duplicate => self.duplicate_host(host_id),
+ RemoteHostCommand::Delete => self.delete_host(host_id),
+ }
+ }
+
+ /// The card under the pointer, if any.
+ fn card_at(&self, x: f32, y: f32) -> Option<usize> {
+ self.card_rects
+ .iter()
+ .rev()
+ .find(|(_, rect)| contains(*rect, x, y))
+ .map(|(index, _)| *index)
+ }
+
+ /// Native context menu for one host card. The page cannot open a menu
+ /// itself -- menus belong to the window -- so it hands the window a
+ /// callback and the window pops it at the same coordinates.
+ fn host_context_menu(&mut self, x: f32, y: f32) -> ContentViewResponse {
+ let Some(index) = self.card_at(x, y) else {
+ return ContentViewResponse::Ignored;
+ };
+ let Some(entry) = self.filtered.get(index) else {
+ return ContentViewResponse::Ignored;
+ };
+ let host_id = entry.id.clone();
+ let label = entry.spec.label.clone();
+ // A host read out of ~/.ssh/config is ours to connect to, not to
+ // rewrite: this page never writes that file back.
+ let editable = entry.source == SshHostSource::ThinkTerm;
+ self.selected = index;
+ self.selection_active = true;
+ ContentViewResponse::Run(Box::new(move |term_window| {
+ term_window.show_remote_host_menu(host_id, label, editable, x, y);
+ }))
+ }
+
fn on_key_impl(&mut self, key: KeyCode, mods: KeyModifiers) -> ContentViewResponse {
// Up/Down drive the host list, so they must reach the navigation match
// below even while a field has focus.
@@ -755,6 +949,7 @@ impl SshHostsView {
self.step_field(1);
} else if !self.filtered.is_empty() {
self.selected = (self.selected + 1).min(self.filtered.len() - 1);
+ self.selection_active = true;
}
ContentViewResponse::Redraw
}
@@ -763,6 +958,7 @@ impl SshHostsView {
self.step_field(-1);
} else {
self.selected = self.selected.saturating_sub(1);
+ self.selection_active = true;
}
ContentViewResponse::Redraw
}
@@ -1011,7 +1207,10 @@ impl SshHostsView {
};
f(input);
if matches!(self.focus, Focus::Search) {
+ // Typing in the search box reshuffles the list under the
+ // highlight, so the old choice no longer means anything.
self.selected = 0;
+ self.selection_active = false;
self.refresh();
}
}
@@ -1024,13 +1223,64 @@ impl SshHostsView {
// ---- paint ------------------------------------------------------------
- fn clamp_left_width(width: f32, total_width: f32) -> f32 {
- let available = (total_width - RIGHT_MIN_W).max(260.0);
- let max_width = available.min(LEFT_MAX_W).max(260.0);
- let min_width = LEFT_MIN_W.min(max_width);
- width.clamp(min_width, max_width)
+ /// Height of a host card: two lines of text plus breathing room.
+ fn card_height(ctx: &DrawContext) -> f32 {
+ (ctx.metrics.cell_size.height as f32 * 2.05 + ctx.px(50.0)).max(ctx.px(104.0))
+ }
+
+ /// One column count shared by both groups, so the two grids line up with
+ /// each other instead of each picking its own width.
+ fn card_columns(ctx: &DrawContext, counts: &[usize], content_width: f32) -> usize {
+ shared_grid_columns(
+ counts,
+ content_width,
+ MAX_CARD_COLUMNS,
+ ctx.px(CARD_MIN_W),
+ ctx.px(CARD_MIN_W + 60.0),
+ ctx.px(CARD_GAP),
+ )
+ }
+
+ /// Indices into `filtered`, split into the two groups the grid draws:
+ /// this app's own hosts first, then whatever `~/.ssh/config` contributed.
+ fn grouped_indices(&self) -> (Vec<usize>, Vec<usize>) {
+ let mut own = Vec::new();
+ let mut system = Vec::new();
+ for (index, entry) in self.filtered.iter().enumerate() {
+ match entry.source {
+ SshHostSource::ThinkTerm => own.push(index),
+ SshHostSource::System => system.push(index),
+ }
+ }
+ (own, system)
+ }
+
+ fn system_group_expanded(&self) -> bool {
+ !self.system_hosts_collapsed || !self.search.text().trim().is_empty()
+ }
+
+ /// What a card says under the host name: where it connects, and -- only
+ /// when it is not plain SSH -- how.
+ ///
+ /// Spelled out after the endpoint rather than shown as a corner tag: a
+ /// two-word tag next to the title has to be read as a label anyway, and
+ /// "connect" as a tag collides with the verb.
+ fn card_subtitle(entry: &SshHostEntry) -> String {
+ let endpoint = ssh_hosts::endpoint(&entry.spec);
+ let mode = if entry.spec.use_mosh {
+ Some(crate::i18n::tr("ssh-mode-mosh"))
+ } else if entry.spec.multiplexing {
+ Some(crate::i18n::tr("ssh-mode-connect"))
+ } else {
+ None
+ };
+ match mode {
+ Some(mode) => format!("{endpoint} · {mode}"),
+ None => endpoint,
+ }
}
+ #[allow(clippy::too_many_arguments)]
fn paint_impl(
&mut self,
ctx: &DrawContext,
@@ -1038,161 +1288,83 @@ impl SshHostsView {
area: RectF,
palette: UiPalette,
font: &Rc<LoadedFont>,
+ title_font: &Rc<LoadedFont>,
+ section_font: &Rc<LoadedFont>,
cursor_on: bool,
) -> anyhow::Result<()> {
let tokens = UiTokens::for_dpi(ctx.dimensions.dpi);
self.refresh();
self.widgets.clear();
+ self.card_rects.clear();
+
+ // Headings need their own context: text sits on the baseline of the
+ // metrics the *context* carries, not of the font handed to draw_text,
+ // so a larger font drawn through the body context lands on the body
+ // baseline and looks a few pixels high.
+ let title_metrics = RenderMetrics::with_font_metrics(&title_font.metrics());
+ let section_metrics = RenderMetrics::with_font_metrics(&section_font.metrics());
+ let title_ctx = ctx.with_metrics(&title_metrics);
+ let section_ctx = ctx.with_metrics(&section_metrics);
let ox = area.origin.x;
let oy = area.origin.y;
let w = area.size.width;
let h = area.size.height;
- self.last_area_x = ox;
- self.last_area_w = w;
self.last_ui_scale = ctx.px(1.0).max(0.01);
- self.left_width = Self::clamp_left_width(self.left_width, w / self.last_ui_scale);
- // Background.
ctx.draw_rect(layers, 0, ox, oy, w, h, palette.window_bg)?;
- let left_w = ctx.px(self.left_width);
- let left_x = ox + ctx.px(PAD);
- let inner_left_w = left_w - ctx.px(PAD * 2.0);
-
- let search_y = oy + ctx.px(PAD + 48.0);
+ let pad = ctx.px(PAD);
+ // The inspector takes its fixed width off the top and the grid lays
+ // out in what is left. That is the whole responsive story: widen the
+ // window and the leftover width becomes more columns, not a wider
+ // form floating in the middle of the page.
+ let inspector_w = if self.form.is_some() {
+ ctx.px(INSPECTOR_W).min(((w - pad * 2.0) * 0.6).max(0.0))
+ } else {
+ 0.0
+ };
+ let inspector_gap = if inspector_w > 0.0 {
+ ctx.px(INSPECTOR_GAP)
+ } else {
+ 0.0
+ };
+ let content_x = ox + pad;
+ let content_w = (w - pad * 2.0 - inspector_w - inspector_gap).max(0.0);
- // Host list.
- let list_top = search_y + ctx.px(INPUT_H + 14.0);
- let list_bottom = oy + h - ctx.px(PAD);
+ let toolbar_y = oy + pad;
+ let toolbar_h = ctx.px(TOOLBAR_H);
+ let list_top = toolbar_y + toolbar_h + ctx.px(TOOLBAR_GAP);
+ let list_bottom = oy + h - pad;
self.list_area = rect(
- left_x,
+ content_x,
list_top,
- inner_left_w,
+ content_w,
(list_bottom - list_top).max(0.0),
);
- if self.filtered.is_empty() && self.system_host_count == 0 {
- self.scroll.set_extents(self.list_area.size.height, 0.0);
- ctx.draw_text(
- layers,
- font,
- left_x,
- list_top + ctx.px(8.0),
- &crate::i18n::tr("ssh-no-hosts"),
- palette.muted_text,
- inner_left_w,
- )?;
- } else {
- let filtered = self.filtered.clone();
- let row_h = Self::host_row_height(ctx);
- let think_count = filtered
- .iter()
- .filter(|entry| entry.source == SshHostSource::ThinkTerm)
- .count();
- let visible_system_count =
- if !self.system_hosts_collapsed || !self.search.text().trim().is_empty() {
- filtered
- .iter()
- .filter(|entry| entry.source == SshHostSource::System)
- .count()
- } else {
- 0
- };
- let mut content_h = Self::rows_height(think_count, row_h, ctx.px(ROW_GAP));
- if self.system_host_count > 0 {
- if content_h > 0.0 {
- content_h += ctx.px(ROW_GAP + 4.0);
- } else {
- content_h += ctx.px(4.0);
- }
- content_h += ctx.px(GROUP_ROW_H + 10.0);
- content_h += Self::rows_height(visible_system_count, row_h, ctx.px(ROW_GAP));
- }
- self.scroll
- .set_extents(self.list_area.size.height, content_h);
-
- let mut row_y = list_top - self.scroll.offset;
- for (i, entry) in filtered
- .iter()
- .enumerate()
- .filter(|(_, entry)| entry.source == SshHostSource::ThinkTerm)
- {
- if row_y > list_bottom {
- break;
- }
- if Self::row_visible(row_y, row_h, list_top, list_bottom) {
- self.paint_host_row(
- ctx,
- layers,
- font,
- palette,
- left_x,
- row_y,
- inner_left_w,
- i,
- entry,
- list_top,
- list_bottom,
- )?;
- }
- row_y += row_h + ctx.px(ROW_GAP);
- }
- if self.system_host_count > 0 {
- row_y += ctx.px(4.0);
- if Self::row_visible(row_y, ctx.px(GROUP_ROW_H), list_top, list_bottom) {
- self.paint_system_group_header(
- ctx,
- layers,
- font,
- palette,
- left_x,
- row_y,
- inner_left_w,
- list_top,
- list_bottom,
- )?;
- row_y += ctx.px(GROUP_ROW_H + 10.0);
- }
- if !self.system_hosts_collapsed || !self.search.text().trim().is_empty() {
- for (i, entry) in filtered
- .iter()
- .enumerate()
- .filter(|(_, entry)| entry.source == SshHostSource::System)
- {
- if row_y > list_bottom {
- break;
- }
- if Self::row_visible(row_y, row_h, list_top, list_bottom) {
- self.paint_host_row(
- ctx,
- layers,
- font,
- palette,
- left_x,
- row_y,
- inner_left_w,
- i,
- entry,
- list_top,
- list_bottom,
- )?;
- }
- row_y += row_h + ctx.px(ROW_GAP);
- }
- }
- }
- }
+ self.paint_grid(
+ ctx,
+ &section_ctx,
+ layers,
+ font,
+ section_font,
+ palette,
+ content_x,
+ content_w,
+ list_top,
+ list_bottom,
+ )?;
- // Mask scrolled rows back out of the fixed header/search area, then
- // repaint the header controls above the list. This mirrors the main
- // workspace sidebar and avoids rows bleeding over "SSH Hosts".
+ // Cards scroll under the toolbar and past the bottom edge. Blank both
+ // strips on every layer, then repaint the toolbar above them.
+ let masked_w = (content_x + content_w) - ox;
self.paint_list_mask(
ctx,
layers,
ox,
oy,
- left_w,
+ masked_w,
(list_top - oy).max(0.0),
palette,
)?;
@@ -1201,255 +1373,490 @@ impl SshHostsView {
layers,
ox,
list_bottom,
- left_w,
+ masked_w,
(oy + h - list_bottom).max(0.0),
palette,
)?;
- self.paint_list_fades(ctx, layers, self.list_area, palette)?;
- self.paint_header_controls(
- ctx,
- layers,
- font,
- left_x,
- oy + ctx.px(PAD),
- search_y,
- inner_left_w,
- palette,
- tokens,
- cursor_on,
+ self.paint_list_fades(ctx, layers, self.list_area, palette, self.scroll)?;
+ self.paint_toolbar(
+ ctx, layers, font, palette, tokens, cursor_on, content_x, toolbar_y, content_w,
)?;
if self.scroll.has_overflow() {
draw_scrollbar(ctx, layers, palette, tokens, self.list_area, self.scroll)?;
}
- // Right pane: form or empty hint.
- let right_x = ox + left_w + ctx.px(PAD);
- let right_w = (ox + w - ctx.px(PAD)) - right_x;
- // Vertical separator.
- let split_x = ox + left_w;
- ctx.draw_rect(
- layers,
- 0,
- split_x,
- oy + ctx.px(PAD),
- if self.dragging_left_pane { 2.0 } else { 1.0 },
- h - ctx.px(PAD * 2.0),
- if self.dragging_left_pane {
- palette.selected_bg
- } else {
- palette.separator
- },
- )?;
- self.widgets.push(
- rect(
- split_x - ctx.px(SPLIT_HANDLE_W / 2.0),
- oy,
- ctx.px(SPLIT_HANDLE_W),
- h,
- ),
- WidgetKind::ResizeHandle,
- SshViewAction::ResizeLeftPane,
- );
-
- if self.form.is_some() {
- let form_top = oy + ctx.px(PAD);
- self.paint_form(
+ if inspector_w > 0.0 {
+ let inspector = rect(
+ ox + w - pad - inspector_w,
+ oy + pad,
+ inspector_w,
+ (h - pad * 2.0).max(0.0),
+ );
+ self.paint_inspector(
ctx,
+ &title_ctx,
+ &section_ctx,
layers,
font,
+ title_font,
+ section_font,
palette,
tokens,
cursor_on,
- right_x,
- form_top,
- right_w,
- (oy + h) - form_top,
+ inspector,
)?;
} else {
- ctx.draw_text(
- layers,
- font,
- right_x,
- oy + h / 2.0 - 10.0,
- &crate::i18n::tr("ssh-select-host"),
- palette.muted_text,
- right_w.max(0.0),
- )?;
+ self.form_area = rect(0.0, 0.0, 0.0, 0.0);
}
Ok(())
}
#[allow(clippy::too_many_arguments)]
- fn paint_header_controls(
+ fn paint_toolbar(
&mut self,
ctx: &DrawContext,
layers: &mut TripleLayerQuadAllocator<'_>,
font: &Rc<LoadedFont>,
- left_x: f32,
- title_y: f32,
- search_y: f32,
- inner_left_w: f32,
palette: UiPalette,
tokens: UiTokens,
cursor_on: bool,
+ x: f32,
+ y: f32,
+ width: f32,
) -> anyhow::Result<()> {
- ctx.draw_text_on_layer(
+ // Everything here is painted on layer 2, above the mask that hides the
+ // cards scrolling underneath.
+ let height = ctx.px(TOOLBAR_H);
+ let new_label = crate::i18n::tr("ssh-new-host");
+ let new_w = (ctx.measure_text_width(font, &new_label) + ctx.px(60.0)).min(width);
+ let new_state = self.button_state(SshViewAction::New);
+ draw_button_on_layer(
+ ctx,
layers,
- 2,
font,
- left_x,
- title_y,
- &crate::i18n::tr("ssh-hosts-title"),
- palette.text,
- inner_left_w,
+ &mut self.widgets,
+ palette,
+ ButtonSpec {
+ label: &new_label,
+ action: SshViewAction::New,
+ rect: rect(x, y, new_w, height),
+ state: new_state,
+ kind: WidgetKind::Button,
+ variant: ButtonVariant::Primary,
+ },
+ 2,
)?;
- let search_rect = rect(
- left_x,
- search_y,
- inner_left_w - ctx.px(INPUT_H + 8.0),
- ctx.px(INPUT_H),
- );
- self.widgets
- .push(search_rect, WidgetKind::TextInput, SshViewAction::Search);
- let search_focused = matches!(self.focus, Focus::Search);
- let search_border = if search_focused {
- palette.selected_bg
- } else if self.interaction.hovered == Some(SshViewAction::Search) {
- palette.separator
- } else {
- palette.control_border
+ let gap = ctx.px(12.0);
+ let search_x = x + new_w + gap;
+ let search_w = (width - new_w - gap).min(ctx.px(SEARCH_W)).max(0.0);
+ if search_w <= 0.0 {
+ return Ok(());
+ }
+ let search_rect = rect(search_x, y, search_w, height);
+ // A magnifier, and the same pill the button next to it is: two
+ // controls sharing a toolbar should share a shape.
+ let glyph = (ctx.metrics.cell_size.height as f32).clamp(ctx.px(18.0), ctx.px(24.0));
+ let text_pad = ctx.px(16.0) + glyph + ctx.px(10.0);
+ let search_tokens = UiTokens {
+ control_radius: height / 2.0,
+ ..tokens
};
- ctx.draw_rounded_frame(
+ let search_text = self.search.text().to_string();
+ self.resolve_pending_caret_click(
+ ctx,
+ font,
+ Focus::Search,
+ &search_text,
+ search_rect.origin.x + text_pad,
+ );
+ let caret = self.caret_for(Focus::Search);
+ draw_text_input_on_layer(
+ ctx,
layers,
+ font,
+ &mut self.widgets,
+ &self.interaction,
+ palette,
+ search_tokens,
+ text_pad,
+ cursor_on,
+ TextInputSpec {
+ placeholder: &crate::i18n::tr("ssh-search"),
+ text: &search_text,
+ rect: search_rect,
+ focused: matches!(self.focus, Focus::Search),
+ selected_all: false,
+ action: SshViewAction::Search,
+ },
+ caret,
2,
- search_rect.origin.x,
- search_rect.origin.y,
- search_rect.size.width,
- search_rect.size.height,
- palette.control_bg,
- search_border,
- tokens.control_radius,
)?;
+ ctx.draw_svg_icon(
+ layers,
+ SvgIcon::Search,
+ search_rect.origin.x + ctx.px(16.0),
+ search_rect.origin.y + (height - glyph) / 2.0,
+ glyph,
+ palette.muted_text,
+ )?;
+ Ok(())
+ }
- // Hand-rolled rather than `draw_text_input` because this box sits on
- // layer 2, above the list's scroll fade. Geometry mirrors that widget,
- // including the design-pixel conversions.
- let text_pad = ctx.px(12.0);
- let text_left = search_rect.origin.x + text_pad;
- let text_area = (search_rect.size.width - text_pad * 2.0).max(0.0);
- let inset_y = ctx.px(5.0);
- let highlight_y = search_rect.origin.y + inset_y;
- let highlight_h = (search_rect.size.height - inset_y * 2.0).max(0.0);
- // Must run before anything borrows `self.search` for the rest of the
- // frame, since it may move the caret.
- let search_text_owned = self.search.text().to_string();
- self.resolve_pending_caret_click(ctx, font, Focus::Search, &search_text_owned, text_left);
- let search_placeholder = crate::i18n::tr("ssh-search");
- let (search_text, search_color) = if search_text_owned.is_empty() && !search_focused {
- (search_placeholder.as_str(), palette.muted_text)
- } else {
- (search_text_owned.as_str(), palette.text)
- };
- let selection = search_focused
- .then(|| self.search.caret_selection_range())
- .flatten()
- .filter(|(start, end)| start != end);
- if let Some((start, end)) = selection {
- let start_x = text_width_to_char(ctx, font, &search_text_owned, start).min(text_area);
- let end_x = text_width_to_char(ctx, font, &search_text_owned, end).min(text_area);
- ctx.draw_rounded_rect(
+ #[allow(clippy::too_many_arguments)]
+ fn paint_grid(
+ &mut self,
+ ctx: &DrawContext,
+ section_ctx: &DrawContext,
+ layers: &mut TripleLayerQuadAllocator<'_>,
+ font: &Rc<LoadedFont>,
+ section_font: &Rc<LoadedFont>,
+ palette: UiPalette,
+ content_x: f32,
+ content_w: f32,
+ list_top: f32,
+ list_bottom: f32,
+ ) -> anyhow::Result<()> {
+ let viewport = rect(
+ content_x,
+ list_top,
+ content_w,
+ (list_bottom - list_top).max(0.0),
+ );
+ if self.filtered.is_empty() && self.system_host_count == 0 {
+ self.scroll.set_extents(viewport.size.height, 0.0);
+ return self.paint_empty_state(ctx, layers, font, palette, viewport);
+ }
+
+ let (own, system) = self.grouped_indices();
+ // A lone "Hosts" caption over the only group on the page is noise;
+ // the captions earn their place once there is a second group to tell
+ // apart from the first.
+ let grouped = self.system_host_count > 0;
+ let counts = [own.len(), system.len()];
+ let columns = Self::card_columns(ctx, &counts, content_w);
+ let gap = ctx.px(CARD_GAP);
+ let card_h = Self::card_height(ctx);
+ let header_h = ctx.px(GROUP_HEADER_H);
+ let max_w = ctx.px(CARD_MAX_W);
+
+ let own_grid = card_grid(own.len(), content_w, columns, max_w, gap, card_h);
+ let system_grid = card_grid(system.len(), content_w, columns, max_w, gap, card_h);
+
+ let title_gap = ctx.px(GROUP_TITLE_GAP);
+ let mut content_h = own_grid.height(gap);
+ if grouped {
+ content_h += (header_h + title_gap) * 2.0 + ctx.px(GROUP_GAP) + system_grid.height(gap);
+ }
+ self.scroll.set_extents(viewport.size.height, content_h);
+
+ let mut y = list_top - self.scroll.offset;
+ if grouped {
+ self.paint_group_header(
+ section_ctx,
layers,
- 2,
- text_left + start_x - ctx.px(4.0),
- highlight_y,
- (end_x - start_x) + ctx.px(8.0),
- highlight_h,
- palette.selected_bg.mul_alpha(0.56),
- (tokens.control_radius - ctx.px(5.0)).max(ctx.px(3.0)),
+ section_font,
+ palette,
+ &crate::i18n::tr("ssh-group-hosts"),
+ None,
+ content_x,
+ y,
+ content_w,
+ viewport,
)?;
+ y += header_h + title_gap;
}
- ctx.draw_text_on_layer(
- layers,
- 2,
- font,
- text_left,
- Self::control_text_y(ctx, search_rect.origin.y, search_rect.size.height),
- search_text,
- search_color,
- text_area,
+ self.paint_cards(
+ ctx, layers, font, palette, &own, own_grid, content_x, content_w, y, gap, viewport,
)?;
- if search_focused && selection.is_none() && cursor_on {
- let caret_dx = text_width_to_char(ctx, font, &search_text_owned, self.search.cursor)
- .min(text_area);
- let caret_width = ctx.px(3.0);
- ctx.draw_rect(
+ y += own_grid.height(gap);
+
+ if grouped {
+ y += ctx.px(GROUP_GAP);
+ let mut args = FluentArgs::new();
+ args.set("count", self.system_host_count);
+ let label = crate::i18n::tr_args("ssh-system-hosts", &args);
+ self.paint_group_header(
+ section_ctx,
layers,
- 2,
- text_left + caret_dx - caret_width / 3.0,
- highlight_y,
- caret_width,
- highlight_h,
- palette.selected_bg,
+ section_font,
+ palette,
+ &label,
+ Some(SshViewAction::ToggleSystemHosts),
+ content_x,
+ y,
+ content_w,
+ viewport,
)?;
- }
-
- let add_x = left_x + inner_left_w - ctx.px(INPUT_H);
- let add_rect = rect(add_x, search_y, ctx.px(INPUT_H), ctx.px(INPUT_H));
- self.widgets
- .push(add_rect, WidgetKind::Button, SshViewAction::New);
- let add_hovered = self.interaction.hovered == Some(SshViewAction::New);
- let add_pressed = self.interaction.pressed == Some(SshViewAction::New);
- let add_bg = if add_pressed {
- palette.control_pressed_bg
- } else if add_hovered {
- palette.control_hover_bg
- } else {
- LinearRgba::TRANSPARENT
- };
- if add_bg.3 > 0.0 {
- ctx.draw_rounded_rect(
+ y += header_h + title_gap;
+ self.paint_cards(
+ ctx,
layers,
- 2,
- add_x,
- search_y,
- ctx.px(INPUT_H),
- ctx.px(INPUT_H),
- add_bg,
- ctx.px(8.0),
+ font,
+ palette,
+ &system,
+ system_grid,
+ content_x,
+ content_w,
+ y,
+ gap,
+ viewport,
)?;
}
- let icon_size = (ctx.metrics.cell_size.height as f32 + 4.0).clamp(20.0, 30.0);
- ctx.draw_svg_icon(
- layers,
- SvgIcon::Plus,
- add_x + (ctx.px(INPUT_H) - icon_size) / 2.0,
- search_y + (ctx.px(INPUT_H) - icon_size) / 2.0,
- icon_size,
- if add_hovered || add_pressed {
- palette.text
- } else {
- palette.muted_text
- },
- )?;
-
Ok(())
}
- fn control_text_y(ctx: &DrawContext, y: f32, height: f32) -> f32 {
- let cell_height = ctx.metrics.cell_size.height as f32;
- y + ((height - cell_height) / 2.0).max(0.0)
+ #[allow(clippy::too_many_arguments)]
+ fn paint_cards(
+ &mut self,
+ ctx: &DrawContext,
+ layers: &mut TripleLayerQuadAllocator<'_>,
+ font: &Rc<LoadedFont>,
+ palette: UiPalette,
+ indices: &[usize],
+ grid: CardGrid,
+ content_x: f32,
+ content_w: f32,
+ cards_y: f32,
+ gap: f32,
+ viewport: RectF,
+ ) -> anyhow::Result<()> {
+ for (slot, &index) in indices.iter().enumerate() {
+ let card = card_rect(
+ slot,
+ indices.len(),
+ grid,
+ content_x,
+ content_w,
+ cards_y,
+ gap,
+ // A list, not a gallery: rows start at the left margin, and
+ // a full row spends whatever the card width cap left over on
+ // its gaps so it still reaches the right one.
+ RowAlign::Justify,
+ );
+ if !card_is_warm(card, viewport, 0.0) {
+ continue;
+ }
+ self.paint_host_card(ctx, layers, font, palette, index, card, viewport)?;
+ }
+ Ok(())
}
- fn paint_list_fades(
- &self,
+ #[allow(clippy::too_many_arguments)]
+ fn paint_host_card(
+ &mut self,
ctx: &DrawContext,
layers: &mut TripleLayerQuadAllocator<'_>,
- area: RectF,
+ font: &Rc<LoadedFont>,
palette: UiPalette,
+ index: usize,
+ card: RectF,
+ viewport: RectF,
) -> anyhow::Result<()> {
- if !self.scroll.has_overflow() || area.size.width <= 0.0 || area.size.height <= 0.0 {
+ let Some(entry) = self.filtered.get(index).cloned() else {
+ return Ok(());
+ };
+ let action = SshViewAction::Card(index);
+ // Only the part inside the viewport is clickable: a card sliding
+ // under the toolbar must not keep taking clicks up there.
+ let Some(visible) = card.intersection(&viewport) else {
+ return Ok(());
+ };
+ self.widgets.push(visible, WidgetKind::SidebarRow, action);
+ self.card_rects.push((index, visible));
+
+ let selected = self.selection_active && self.selected == index;
+ let hovered = self.interaction.hovered == Some(action);
+ // Selection is a ring, not a wash: the card already carries a logo
+ // and two lines of text, and lightening it as well says the same
+ // thing twice.
+ let bg = if hovered {
+ palette.sidebar_row_hover_bg
+ } else {
+ palette.card_bg
+ };
+ ctx.draw_rounded_frame(
+ layers,
+ 0,
+ card.origin.x,
+ card.origin.y,
+ card.size.width,
+ card.size.height,
+ bg,
+ if selected {
+ palette.accent
+ } else {
+ palette.separator
+ },
+ ctx.px(CARD_RADIUS),
+ )?;
+ if selected {
+ // A second ring just inside the first: one device pixel of accent
+ // disappears on a retina display.
+ ctx.draw_rounded_frame(
+ layers,
+ 0,
+ card.origin.x + 1.0,
+ card.origin.y + 1.0,
+ card.size.width - 2.0,
+ card.size.height - 2.0,
+ LinearRgba::TRANSPARENT,
+ palette.accent,
+ ctx.px(CARD_RADIUS) - 1.0,
+ )?;
+ }
+
+ let pad = ctx.px(CARD_PAD);
+ let line_h = ctx.metrics.cell_size.height as f32;
+ // The logo is how you pick a machine out of the grid without
+ // reading, so it gets real estate: roughly half the card's height.
+ let icon = (line_h * 2.2).clamp(ctx.px(50.0), ctx.px(64.0));
+ let icon_x = card.origin.x + pad;
+ let icon_y = card.origin.y + (card.size.height - icon) / 2.0;
+ match entry
+ .spec
+ .detected_distro
+ .as_deref()
+ .and_then(distro_to_icon)
+ {
+ Some(brand) => ctx.draw_brand_icon(layers, brand, icon_x, icon_y, icon)?,
+ None => ctx.draw_svg_icon(
+ layers,
+ SvgIcon::Server,
+ icon_x,
+ icon_y,
+ icon,
+ palette.muted_text,
+ )?,
+ }
+
+ let text_x = icon_x + icon + ctx.px(14.0);
+ let text_w = (card.max_x() - pad - text_x).max(0.0);
+ let stack = line_h * 2.0 + ctx.px(4.0);
+ let title_y = card.origin.y + ((card.size.height - stack) / 2.0).max(ctx.px(8.0));
+ ctx.draw_text(
+ layers,
+ font,
+ text_x,
+ title_y,
+ &entry.spec.label,
+ palette.text,
+ text_w,
+ )?;
+ ctx.draw_text(
+ layers,
+ font,
+ text_x,
+ title_y + line_h + ctx.px(4.0),
+ &Self::card_subtitle(&entry),
+ palette.muted_text,
+ text_w,
+ )?;
+ Ok(())
+ }
+
+ #[allow(clippy::too_many_arguments)]
+ fn paint_group_header(
+ &mut self,
+ section_ctx: &DrawContext,
+ layers: &mut TripleLayerQuadAllocator<'_>,
+ section_font: &Rc<LoadedFont>,
+ palette: UiPalette,
+ label: &str,
+ toggle: Option<SshViewAction>,
+ x: f32,
+ y: f32,
+ width: f32,
+ viewport: RectF,
+ ) -> anyhow::Result<()> {
+ let height = section_ctx.px(GROUP_HEADER_H);
+ if !row_visible(y, height, viewport) {
+ return Ok(());
+ }
+ let line_h = section_ctx.metrics.cell_size.height as f32;
+ let mut text_x = x;
+ if let Some(action) = toggle {
+ let hit_h = (y + height).min(viewport.max_y()) - y.max(viewport.min_y());
+ self.widgets.push(
+ rect(x, y.max(viewport.min_y()), width, hit_h.max(0.0)),
+ WidgetKind::Button,
+ action,
+ );
+ let chevron = section_ctx.px(18.0);
+ let icon = if self.system_group_expanded() {
+ SvgIcon::ChevronDown
+ } else {
+ SvgIcon::ChevronRight
+ };
+ section_ctx.draw_svg_icon(
+ layers,
+ icon,
+ x,
+ y + (height - chevron) / 2.0,
+ chevron,
+ palette.muted_text,
+ )?;
+ text_x += chevron + section_ctx.px(6.0);
+ }
+ section_ctx.draw_text(
+ layers,
+ section_font,
+ text_x,
+ y + ((height - line_h) / 2.0).max(0.0),
+ label,
+ palette.secondary_text,
+ (width - (text_x - x)).max(0.0),
+ )?;
+ Ok(())
+ }
+
+ fn paint_empty_state(
+ &mut self,
+ ctx: &DrawContext,
+ layers: &mut TripleLayerQuadAllocator<'_>,
+ font: &Rc<LoadedFont>,
+ palette: UiPalette,
+ viewport: RectF,
+ ) -> anyhow::Result<()> {
+ if viewport.size.width <= 0.0 || viewport.size.height <= 0.0 {
+ return Ok(());
+ }
+ let icon = ctx.px(56.0);
+ let center_x = viewport.origin.x + viewport.size.width / 2.0;
+ let center_y = viewport.origin.y + viewport.size.height / 2.0;
+ ctx.draw_svg_icon(
+ layers,
+ SvgIcon::Server,
+ center_x - icon / 2.0,
+ center_y - icon - ctx.px(10.0),
+ icon,
+ palette.muted_text,
+ )?;
+ let message = crate::i18n::tr("ssh-no-hosts");
+ let width = ctx.measure_text_width(font, &message);
+ ctx.draw_text(
+ layers,
+ font,
+ center_x - width / 2.0,
+ center_y + ctx.px(8.0),
+ &message,
+ palette.muted_text,
+ viewport.size.width,
+ )?;
+ Ok(())
+ }
+
+ fn paint_list_fades(
+ &self,
+ ctx: &DrawContext,
+ layers: &mut TripleLayerQuadAllocator<'_>,
+ area: RectF,
+ palette: UiPalette,
+ scroll: ScrollState,
+ ) -> anyhow::Result<()> {
+ if !scroll.has_overflow() || area.size.width <= 0.0 || area.size.height <= 0.0 {
return Ok(());
}
@@ -1458,7 +1865,7 @@ impl SshHostsView {
return Ok(());
}
- if self.scroll.offset > 0.5 {
+ if scroll.offset > 0.5 {
for step in 0..fade_height {
let progress = step as f32 / fade_height as f32;
let alpha = 1.0 - Easing::Smooth.apply(progress);
@@ -1474,7 +1881,7 @@ impl SshHostsView {
}
}
- if self.scroll.offset < self.scroll.max_offset() - 0.5 {
+ if scroll.offset < scroll.max_offset() - 0.5 {
let start_y = area.origin.y + area.size.height - fade_height as f32;
for step in 0..fade_height {
let progress = (step + 1) as f32 / fade_height as f32;
@@ -1514,622 +1921,767 @@ impl SshHostsView {
}
#[allow(clippy::too_many_arguments)]
- fn paint_system_group_header(
+
+ /// Height of one label-over-input field row.
+ fn field_row_height(ctx: &DrawContext) -> f32 {
+ ctx.metrics.cell_size.height as f32 + ctx.px(LABEL_GAP) + ctx.px(INPUT_H)
+ }
+
+ fn toggle_row_height(ctx: &DrawContext) -> f32 {
+ ctx.px(40.0)
+ .max(ctx.metrics.cell_size.height as f32 + ctx.px(10.0))
+ }
+
+ /// A card tall enough for `rows`, including its caption and padding.
+ fn inspector_card_height(ctx: &DrawContext, section_h: f32, rows: &[f32]) -> f32 {
+ let gap = ctx.px(FIELD_GAP);
+ ctx.px(20.0) * 2.0
+ + section_h
+ + ctx.px(12.0)
+ + rows.iter().sum::<f32>()
+ + gap * rows.len().saturating_sub(1) as f32
+ }
+
+ /// Draw a card and its caption; returns the y of its first row.
+ #[allow(clippy::too_many_arguments)]
+ fn paint_inspector_card(
+ ctx: &DrawContext,
+ section_ctx: &DrawContext,
+ layers: &mut TripleLayerQuadAllocator<'_>,
+ section_font: &Rc<LoadedFont>,
+ palette: UiPalette,
+ tokens: UiTokens,
+ caption: &str,
+ area: RectF,
+ ) -> anyhow::Result<f32> {
+ ctx.draw_card(layers, 0, area, palette, tokens)?;
+ let pad = ctx.px(20.0);
+ let section_h = section_ctx.metrics.cell_size.height as f32;
+ section_ctx.draw_text(
+ layers,
+ section_font,
+ area.origin.x + pad,
+ area.origin.y + pad,
+ caption,
+ palette.secondary_text,
+ (area.size.width - pad * 2.0).max(0.0),
+ )?;
+ Ok(area.origin.y + pad + section_h + ctx.px(12.0))
+ }
+
+ #[allow(clippy::too_many_arguments)]
+ fn paint_field(
&mut self,
ctx: &DrawContext,
layers: &mut TripleLayerQuadAllocator<'_>,
font: &Rc<LoadedFont>,
palette: UiPalette,
+ tokens: UiTokens,
+ cursor_on: bool,
+ label: &str,
+ index: usize,
+ shown: &str,
x: f32,
y: f32,
width: f32,
- list_top: f32,
- list_bottom: f32,
- ) -> anyhow::Result<()> {
- let hit_y = y.max(list_top);
- let hit_h = (y + ctx.px(GROUP_ROW_H)).min(list_bottom) - hit_y;
- let rect = rect(x, hit_y, width, hit_h.max(0.0));
- self.widgets.push(
- rect,
- WidgetKind::SidebarRow,
- SshViewAction::ToggleSystemHosts,
- );
- let hovered = self.interaction.hovered == Some(SshViewAction::ToggleSystemHosts);
- if hovered {
- ctx.draw_rounded_rect(
- layers,
- 0,
- x,
- y,
- width,
- ctx.px(GROUP_ROW_H),
- palette.sidebar_row_hover_bg,
- 10.0,
- )?;
- }
- let icon = if self.system_hosts_collapsed && self.search.text().trim().is_empty() {
- SvgIcon::ChevronRight
- } else {
- SvgIcon::ChevronDown
- };
- ctx.draw_svg_icon(layers, icon, x + 12.0, y + 12.0, 20.0, palette.muted_text)?;
- let mut args = FluentArgs::new();
- args.set("count", self.system_host_count);
- let label = crate::i18n::tr_args("ssh-system-hosts", &args);
- ctx.draw_text(
+ ) -> anyhow::Result<f32> {
+ let line_h = ctx.metrics.cell_size.height as f32;
+ ctx.draw_text(layers, font, x, y, label, palette.muted_text, width)?;
+ let input_y = y + line_h + ctx.px(LABEL_GAP);
+ let text_pad = ctx.px(12.0);
+ self.resolve_pending_caret_click(ctx, font, Focus::Field(index), shown, x + text_pad);
+ let caret = self.caret_for(Focus::Field(index));
+ let focused = self.focus == Focus::Field(index);
+ draw_text_input(
+ ctx,
layers,
font,
- x + ctx.px(42.0),
- y + ctx.px(8.0),
- &label,
- palette.muted_text,
- (width - 50.0).max(0.0),
+ &mut self.widgets,
+ &self.interaction,
+ palette,
+ tokens,
+ text_pad,
+ cursor_on,
+ TextInputSpec {
+ placeholder: "",
+ text: shown,
+ rect: rect(x, input_y, width, ctx.px(INPUT_H)),
+ focused,
+ selected_all: false,
+ action: SshViewAction::FocusField(index),
+ },
+ caret,
)?;
- Ok(())
- }
-
- fn host_row_height(ctx: &DrawContext) -> f32 {
- (ctx.metrics.cell_size.height as f32 * 2.15 + ctx.px(26.0)).max(ctx.px(ROW_MIN_H))
- }
-
- fn rows_height(count: usize, row_h: f32, row_gap: f32) -> f32 {
- if count == 0 {
- 0.0
- } else {
- count as f32 * row_h + (count.saturating_sub(1)) as f32 * row_gap
- }
- }
-
- fn row_visible(y: f32, height: f32, list_top: f32, list_bottom: f32) -> bool {
- y + height >= list_top && y <= list_bottom
+ Ok(input_y + ctx.px(INPUT_H))
}
#[allow(clippy::too_many_arguments)]
- fn paint_host_row(
+ fn paint_toggle_row(
&mut self,
ctx: &DrawContext,
layers: &mut TripleLayerQuadAllocator<'_>,
font: &Rc<LoadedFont>,
palette: UiPalette,
+ label: &str,
+ on: bool,
+ action: SshViewAction,
x: f32,
y: f32,
width: f32,
- index: usize,
- entry: &SshHostEntry,
- list_top: f32,
- list_bottom: f32,
- ) -> anyhow::Result<()> {
- let spec = &entry.spec;
- let row_h = Self::host_row_height(ctx);
- let hit_y = y.max(list_top);
- let hit_h = (y + row_h).min(list_bottom) - hit_y;
- let row_rect = rect(x, hit_y, width, hit_h.max(0.0));
- self.widgets.push(
- row_rect,
- WidgetKind::SidebarRow,
- SshViewAction::Connect(index),
- );
-
- let selected = index == self.selected;
- let hovered = self.interaction.hovered == Some(SshViewAction::Connect(index));
- let bg = if selected {
- palette.sidebar_row_active_bg
- } else if hovered {
- palette.sidebar_row_hover_bg
- } else {
- LinearRgba::TRANSPARENT
- };
- if bg.3 > 0.0 {
- ctx.draw_rounded_rect(layers, 0, x, y, width, row_h, bg, ctx.px(HOST_ROW_RADIUS))?;
- }
-
- // OS / brand icon.
+ ) -> anyhow::Result<f32> {
+ let height = Self::toggle_row_height(ctx);
let line_h = ctx.metrics.cell_size.height as f32;
- let icon_size = (line_h * 1.05).clamp(ctx.px(34.0), ctx.px(48.0));
- let icon_x = x + ctx.px(12.0);
- let icon_y = y + (row_h - icon_size) / 2.0;
- match spec.detected_distro.as_deref().and_then(distro_to_icon) {
- Some(brand) => ctx.draw_brand_icon(layers, brand, icon_x, icon_y, icon_size)?,
- None => ctx.draw_svg_icon(
- layers,
- SvgIcon::Server,
- icon_x,
- icon_y,
- icon_size,
- palette.text,
- )?,
- }
-
- let text_x = icon_x + icon_size + ctx.px(14.0);
- let action_space = if entry.source == SshHostSource::ThinkTerm {
- ctx.px(HOST_ACTION_RIGHT_PAD + HOST_ACTION_BTN * 2.0 + HOST_ACTION_GAP + 10.0)
- } else {
- ctx.px(16.0)
- };
- let text_w = width - (text_x - x) - action_space;
- let stack_h = line_h * 2.02;
- let title_y = y + ((row_h - stack_h) / 2.0).max(ctx.px(8.0)) - ctx.px(2.0);
- let subtitle_y = (title_y + line_h * 1.02).min(y + row_h - line_h - ctx.px(8.0));
+ let toggle_w = ctx.px(64.0);
+ let toggle_h = ctx.px(36.0);
ctx.draw_text(
layers,
font,
- text_x,
- title_y,
- &spec.label,
+ x,
+ y + ((height - line_h) / 2.0).max(0.0),
+ label,
palette.text,
- text_w.max(0.0),
+ (width - toggle_w - ctx.px(12.0)).max(0.0),
)?;
- let subtitle = {
- let user = spec.username.as_deref().unwrap_or("");
- let source = if spec.use_mosh {
- "mosh"
- } else if spec.multiplexing {
- "thinkterm connect"
- } else {
- match entry.source {
- SshHostSource::ThinkTerm => "ssh",
- SshHostSource::System => "system ssh",
- }
- };
- if user.is_empty() {
- source.to_string()
- } else {
- format!("{source}, {user}")
- }
- };
- ctx.draw_text(
- layers,
- font,
- text_x,
- subtitle_y,
- &subtitle,
- palette.muted_text,
- text_w.max(0.0),
- )?;
-
- // Edit + delete icon buttons (right aligned). System SSH config hosts
- // are read-only here: connect only, no write-back.
- if entry.source == SshHostSource::System {
- return Ok(());
- }
- let btn = ctx.px(HOST_ACTION_BTN);
- let btn_y = y + (row_h - btn) / 2.0;
- draw_icon_button(
- ctx,
- layers,
- &mut self.widgets,
- &self.interaction,
- palette,
- x + width - ctx.px(HOST_ACTION_RIGHT_PAD) - btn * 2.0 - ctx.px(HOST_ACTION_GAP),
- btn_y,
- btn,
- SvgIcon::SlidersHorizontal,
- SshViewAction::Edit(index),
- )?;
- draw_icon_button(
+ draw_toggle(
ctx,
layers,
&mut self.widgets,
&self.interaction,
palette,
- x + width - ctx.px(HOST_ACTION_RIGHT_PAD) - btn,
- btn_y,
- btn,
- SvgIcon::Trash2,
- SshViewAction::Delete(index),
+ rect(
+ x + width - toggle_w,
+ y + (height - toggle_h) / 2.0,
+ toggle_w,
+ toggle_h,
+ ),
+ on,
+ action,
)?;
- Ok(())
+ Ok(y + height)
}
#[allow(clippy::too_many_arguments)]
- fn paint_form(
+ fn paint_inspector(
&mut self,
ctx: &DrawContext,
+ title_ctx: &DrawContext,
+ section_ctx: &DrawContext,
layers: &mut TripleLayerQuadAllocator<'_>,
font: &Rc<LoadedFont>,
+ title_font: &Rc<LoadedFont>,
+ section_font: &Rc<LoadedFont>,
palette: UiPalette,
tokens: UiTokens,
cursor_on: bool,
- x: f32,
- y: f32,
- width: f32,
- height: f32,
+ area: RectF,
) -> anyhow::Result<()> {
- let form = self.form.as_ref().unwrap();
- let editing = form.editing.is_some();
+ let Some(form) = self.form.as_ref() else {
+ return Ok(());
+ };
+ let editing = form.editing.clone();
let detect_os = form.detect_os;
let use_mosh = form.use_mosh;
let multiplexing = form.multiplexing;
- let fields = form.fields.clone();
- let options = form.options.clone();
let advanced_open = form.advanced_open;
let error = form.error.clone();
- let focus = self.focus;
+ let fields = form.fields.clone();
+ let options = form.options.clone();
+ let password_visible = self.password_visible;
- // A form pinned to the left of a wide column reads badly, so cap the
- // width and centre what is left over.
- let field_w = width.min(ctx.px(560.0));
- let x = x + ((width - field_w) / 2.0).max(0.0);
- self.form_area = rect(x, y, field_w, height);
- self.form_scroll.set_extents(height, self.form_content_h);
- let top = y - self.form_scroll.offset;
- let mut cur_y = top;
-
- ctx.draw_text(
- layers,
- font,
- x,
- cur_y,
- &crate::i18n::tr(if editing {
- "ssh-edit-host"
- } else {
- "ssh-new-host"
- }),
- palette.text,
- field_w,
- )?;
- cur_y += ctx.metrics.cell_size.height as f32 + ctx.px(18.0);
+ self.form_area = area;
+ let x = area.origin.x;
+ let w = area.size.width;
+ let pad = ctx.px(20.0);
+ let inner = (w - pad * 2.0).max(0.0);
let line_h = ctx.metrics.cell_size.height as f32;
- for (i, label_key) in FIELD_LABEL_KEYS.iter().enumerate() {
- if let Some(heading_key) = FIELD_GROUP_HEADING_KEYS
- .iter()
- .find_map(|(at, heading)| (*at == i).then_some(*heading))
- {
- cur_y += ctx.px(if i == 0 { 0.0 } else { 10.0 });
- ctx.draw_text(
- layers,
- font,
- x,
- cur_y,
- &crate::i18n::tr(heading_key),
- palette.text,
- field_w,
- )?;
- cur_y += line_h + ctx.px(10.0);
+ let section_h = section_ctx.metrics.cell_size.height as f32;
+ let title_h = title_ctx.metrics.cell_size.height as f32;
+ let field_h = Self::field_row_height(ctx);
+ let toggle_h = Self::toggle_row_height(ctx);
+ let gap = ctx.px(FIELD_GAP);
+ let card_gap = ctx.px(INSPECTOR_CARD_GAP);
+
+ // The header does not scroll. It names the machine you are editing
+ // and carries the one action you came for, and both stop meaning
+ // anything the moment they slide off the top of the panel -- which is
+ // exactly what they used to do, taking half the Connect button with
+ // them.
+ let name = fields[FIELD_NAME].text().to_string();
+ let heading = if !name.trim().is_empty() {
+ name
+ } else if editing.is_some() {
+ crate::i18n::tr("ssh-edit-host")
+ } else {
+ crate::i18n::tr("ssh-new-host")
+ };
+ let host = fields[FIELD_HOST].text().to_string();
+ let endpoint = (!host.trim().is_empty()).then(|| {
+ let user = fields[FIELD_USER].text().to_string();
+ let port = fields[FIELD_PORT].text().to_string();
+ let mut endpoint = host.trim().to_string();
+ if !port.trim().is_empty() && port.trim() != "22" {
+ endpoint = format!("{endpoint}:{}", port.trim());
}
- ctx.draw_text(
- layers,
+ if !user.trim().is_empty() {
+ endpoint = format!("{}@{endpoint}", user.trim());
+ }
+ endpoint
+ });
+ // Connect is only meaningful once the host exists on disk; before
+ // that, "Save & Open" at the bottom is the way through.
+ let connect = editing.is_some();
+ let mut header_h = title_h + ctx.px(4.0);
+ if endpoint.is_some() {
+ header_h += line_h;
+ }
+ header_h += ctx.px(14.0);
+ if connect {
+ header_h += ctx.px(BTN_H) + card_gap;
+ }
+
+ let body_top = area.origin.y + header_h;
+ let body_height = (area.max_y() - body_top).max(0.0);
+ self.form_scroll
+ .set_extents(body_height, self.form_content_h);
+ let top = body_top - self.form_scroll.offset;
+ let mut y = top;
+ // The body is recorded and replayed clipped to its own bounds. A mask
+ // cannot fix this one: a card scrolled far enough up is drawn *above*
+ // this view's area entirely -- over the tab bar -- and painting there
+ // to hide it would erase the tab bar with it.
+ let mut heap = HeapQuadAllocator::default();
+ // Where the body's hit targets start, so they can be bounded to the
+ // body once its height is known. Clipping the replay below bounds the
+ // pixels only; a field scrolled above `body_top` would otherwise keep
+ // taking clicks in the header band, where it is invisible.
+ let body_widgets_start = self.widgets.len();
+ {
+ let mut body_layers = TripleLayerQuadAllocator::Heap(&mut heap);
+
+ // ---- Connection
+ let conn_h = Self::inspector_card_height(ctx, section_h, &[field_h, field_h, field_h]);
+ let mut fy = Self::paint_inspector_card(
+ ctx,
+ section_ctx,
+ &mut body_layers,
+ section_font,
+ palette,
+ tokens,
+ &crate::i18n::tr("ssh-group-connection"),
+ rect(x, y, w, conn_h),
+ )?;
+ fy = self.paint_field(
+ ctx,
+ &mut body_layers,
font,
- x,
- cur_y,
- &crate::i18n::tr(label_key),
- palette.muted_text,
- field_w,
+ palette,
+ tokens,
+ cursor_on,
+ &crate::i18n::tr("ssh-field-name"),
+ FIELD_NAME,
+ &fields[FIELD_NAME].text(),
+ x + pad,
+ fy,
+ inner,
+ )? + gap;
+ // Host and Port share a row: a port needs four characters, not a
+ // column of its own.
+ let port_w = ctx.px(96.0).min(inner * 0.32);
+ let host_w = (inner - port_w - ctx.px(10.0)).max(0.0);
+ self.paint_field(
+ ctx,
+ &mut body_layers,
+ font,
+ palette,
+ tokens,
+ cursor_on,
+ &crate::i18n::tr("ssh-field-host"),
+ FIELD_HOST,
+ &fields[FIELD_HOST].text(),
+ x + pad,
+ fy,
+ host_w,
)?;
- let input_y = cur_y + line_h + ctx.px(6.0);
- // Mask the password field.
- let masked = if i == FIELD_PASSWORD {
- "•".repeat(fields[i].text().chars().count())
- } else {
- String::new()
- };
- let shown: &str = if i == FIELD_PASSWORD {
- &masked
- } else {
- &fields[i].text()
- };
- // Resolved up front: the call below borrows `self.widgets` mutably.
- self.resolve_pending_caret_click(ctx, font, Focus::Field(i), shown, x + ctx.px(12.0));
- let field_caret = self.caret_for(Focus::Field(i));
- draw_text_input(
+ fy = self.paint_field(
ctx,
- layers,
+ &mut body_layers,
font,
- &mut self.widgets,
- &self.interaction,
palette,
tokens,
- ctx.px(12.0),
cursor_on,
- TextInputSpec {
- placeholder: "",
- text: shown,
- rect: rect(x, input_y, field_w, ctx.px(INPUT_H)),
- focused: focus == Focus::Field(i),
- selected_all: false,
- action: SshViewAction::FocusField(i),
- },
- field_caret,
+ &crate::i18n::tr("ssh-field-port"),
+ FIELD_PORT,
+ &fields[FIELD_PORT].text(),
+ x + pad + host_w + ctx.px(10.0),
+ fy,
+ port_w,
+ )? + gap;
+ self.paint_field(
+ ctx,
+ &mut body_layers,
+ font,
+ palette,
+ tokens,
+ cursor_on,
+ &crate::i18n::tr("ssh-field-user"),
+ FIELD_USER,
+ &fields[FIELD_USER].text(),
+ x + pad,
+ fy,
+ inner,
)?;
- cur_y = input_y + ctx.px(INPUT_H + 18.0);
- }
-
- // Detect-OS toggle.
- let toggle_w = ctx.px(44.0);
- let toggle_h = ctx.px(24.0);
- ctx.draw_text(
- layers,
- font,
- x,
- cur_y + (toggle_h - line_h) / 2.0,
- &crate::i18n::tr("ssh-detect-os"),
- palette.text,
- field_w - toggle_w - ctx.px(12.0),
- )?;
- draw_toggle(
- ctx,
- layers,
- &mut self.widgets,
- palette,
- rect(x + field_w - toggle_w, cur_y, toggle_w, toggle_h),
- detect_os,
- SshViewAction::ToggleDetect,
- )?;
- cur_y += toggle_h + ctx.px(24.0);
-
- // Use-Mosh toggle: connect by launching the local `mosh` client instead
- // of the SSH domain.
- ctx.draw_text(
- layers,
- font,
- x,
- cur_y + (toggle_h - line_h) / 2.0,
- &crate::i18n::tr("ssh-use-mosh"),
- palette.text,
- field_w - toggle_w - ctx.px(12.0),
- )?;
- draw_toggle(
- ctx,
- layers,
- &mut self.widgets,
- palette,
- rect(x + field_w - toggle_w, cur_y, toggle_w, toggle_h),
- use_mosh,
- SshViewAction::ToggleMosh,
- )?;
- cur_y += toggle_h + ctx.px(24.0);
+ y += conn_h + card_gap;
- if use_mosh {
- self.resolve_pending_caret_click(
+ // ---- Authentication
+ let auth_h = Self::inspector_card_height(ctx, section_h, &[field_h, field_h]);
+ let mut fy = Self::paint_inspector_card(
ctx,
- font,
- Focus::Field(FIELD_MOSH_SERVER),
- &fields[FIELD_MOSH_SERVER].text(),
- x + ctx.px(12.0),
- );
- let mosh_caret = self.caret_for(Focus::Field(FIELD_MOSH_SERVER));
- draw_text_input(
+ section_ctx,
+ &mut body_layers,
+ section_font,
+ palette,
+ tokens,
+ &crate::i18n::tr("ssh-group-authentication"),
+ rect(x, y, w, auth_h),
+ )?;
+ let raw_password = fields[FIELD_PASSWORD].text().to_string();
+ let masked = "•".repeat(raw_password.chars().count());
+ let eye = ctx.px(INPUT_H);
+ let password_w = (inner - eye - ctx.px(8.0)).max(0.0);
+ self.paint_field(
ctx,
- layers,
+ &mut body_layers,
font,
+ palette,
+ tokens,
+ cursor_on,
+ &crate::i18n::tr("ssh-field-password"),
+ FIELD_PASSWORD,
+ if password_visible {
+ &raw_password
+ } else {
+ &masked
+ },
+ x + pad,
+ fy,
+ password_w,
+ )?;
+ draw_icon_button(
+ ctx,
+ &mut body_layers,
&mut self.widgets,
&self.interaction,
palette,
+ x + pad + password_w + ctx.px(8.0),
+ fy + line_h + ctx.px(LABEL_GAP),
+ eye,
+ if password_visible {
+ SvgIcon::EyeOff
+ } else {
+ SvgIcon::Eye
+ },
+ SshViewAction::RevealPassword,
+ )?;
+ fy += field_h + gap;
+ self.paint_field(
+ ctx,
+ &mut body_layers,
+ font,
+ palette,
tokens,
- ctx.px(12.0),
cursor_on,
- TextInputSpec {
- placeholder: ssh_hosts::DEFAULT_MOSH_SERVER_COMMAND,
- text: &fields[FIELD_MOSH_SERVER].text(),
- rect: rect(x, cur_y, field_w, ctx.px(INPUT_H)),
- focused: focus == Focus::Field(FIELD_MOSH_SERVER),
- selected_all: false,
- action: SshViewAction::FocusField(FIELD_MOSH_SERVER),
- },
- mosh_caret,
+ &crate::i18n::tr("ssh-field-identity"),
+ FIELD_IDENTITY,
+ &fields[FIELD_IDENTITY].text(),
+ x + pad,
+ fy,
+ inner,
)?;
- cur_y += ctx.px(INPUT_H + 24.0);
- }
+ y += auth_h + card_gap;
- // ThinkTerm-Connect toggle: attach the persistent remote mux domain
- // (`thinkterm connect`) instead of a direct SSH session. Requires a
- // thinkterm/wezterm binary on the remote host.
- ctx.draw_text(
- layers,
- font,
- x,
- cur_y + (toggle_h - line_h) / 2.0,
- &crate::i18n::tr("ssh-use-mux"),
- palette.text,
- field_w - toggle_w - ctx.px(12.0),
- )?;
- draw_toggle(
- ctx,
- layers,
- &mut self.widgets,
- palette,
- rect(x + field_w - toggle_w, cur_y, toggle_w, toggle_h),
- multiplexing,
- SshViewAction::ToggleMux,
- )?;
- cur_y += toggle_h + ctx.px(24.0);
-
- // Advanced: raw ssh_config overrides (ProxyJump, ServerAliveInterval,
- // …). `build_ssh_domain` already feeds these straight into the ssh
- // config, so nothing downstream needs to change.
- let disclosure = if advanced_open { "▾" } else { "▸" };
- let advanced_h = line_h + ctx.px(12.0);
- self.widgets.push(
- rect(x, cur_y, field_w, advanced_h),
- WidgetKind::Button,
- SshViewAction::ToggleAdvanced,
- );
- ctx.draw_text(
- layers,
- font,
- x,
- cur_y + (advanced_h - line_h) / 2.0,
- &format!("{disclosure} {}", crate::i18n::tr("ssh-advanced")),
- palette.text,
- field_w,
- )?;
- cur_y += advanced_h + ctx.px(8.0);
-
- if advanced_open {
- let remove_w = ctx.px(INPUT_H);
- let gap = ctx.px(8.0);
- let pair_w = (field_w - remove_w - gap * 2.0).max(0.0);
- let key_w = pair_w * 0.42;
- let value_w = pair_w - key_w;
- for (index, (key, value)) in options.iter().enumerate() {
- let key_x = x;
- let value_x = key_x + key_w + gap;
+ // ---- Session
+ let mut session_rows = vec![field_h, toggle_h, toggle_h, toggle_h];
+ if use_mosh {
+ session_rows.push(field_h);
+ }
+ let session_h = Self::inspector_card_height(ctx, section_h, &session_rows);
+ let mut fy = Self::paint_inspector_card(
+ ctx,
+ section_ctx,
+ &mut body_layers,
+ section_font,
+ palette,
+ tokens,
+ &crate::i18n::tr("ssh-group-session"),
+ rect(x, y, w, session_h),
+ )?;
+ fy = self.paint_field(
+ ctx,
+ &mut body_layers,
+ font,
+ palette,
+ tokens,
+ cursor_on,
+ &crate::i18n::tr("ssh-field-workspace"),
+ FIELD_WORKSPACE,
+ &fields[FIELD_WORKSPACE].text(),
+ x + pad,
+ fy,
+ inner,
+ )? + gap;
+ fy = self.paint_toggle_row(
+ ctx,
+ &mut body_layers,
+ font,
+ palette,
+ &crate::i18n::tr("ssh-detect-os"),
+ detect_os,
+ SshViewAction::ToggleDetect,
+ x + pad,
+ fy,
+ inner,
+ )? + gap;
+ fy = self.paint_toggle_row(
+ ctx,
+ &mut body_layers,
+ font,
+ palette,
+ &crate::i18n::tr("ssh-use-mosh"),
+ use_mosh,
+ SshViewAction::ToggleMosh,
+ x + pad,
+ fy,
+ inner,
+ )? + gap;
+ fy = self.paint_toggle_row(
+ ctx,
+ &mut body_layers,
+ font,
+ palette,
+ &crate::i18n::tr("ssh-use-mux"),
+ multiplexing,
+ SshViewAction::ToggleMux,
+ x + pad,
+ fy,
+ inner,
+ )? + gap;
+ if use_mosh {
+ let mosh = fields[FIELD_MOSH_SERVER].text().to_string();
+ let text_pad = ctx.px(12.0);
self.resolve_pending_caret_click(
ctx,
font,
- Focus::OptionKey(index),
- &key.text(),
- key_x + ctx.px(12.0),
+ Focus::Field(FIELD_MOSH_SERVER),
+ &mosh,
+ x + pad + text_pad,
);
- let key_caret = self.caret_for(Focus::OptionKey(index));
+ let caret = self.caret_for(Focus::Field(FIELD_MOSH_SERVER));
+ let focused = self.focus == Focus::Field(FIELD_MOSH_SERVER);
+ ctx.draw_text(
+ &mut body_layers,
+ font,
+ x + pad,
+ fy,
+ // The row had no name: it printed the default command as
+ // its own label and again as the placeholder.
+ &crate::i18n::tr("ssh-field-mosh-server"),
+ palette.muted_text,
+ inner,
+ )?;
draw_text_input(
ctx,
- layers,
+ &mut body_layers,
font,
&mut self.widgets,
&self.interaction,
palette,
tokens,
- ctx.px(12.0),
+ text_pad,
cursor_on,
TextInputSpec {
- placeholder: "ProxyJump",
- text: &key.text(),
- rect: rect(key_x, cur_y, key_w, ctx.px(INPUT_H)),
- focused: focus == Focus::OptionKey(index),
+ placeholder: ssh_hosts::DEFAULT_MOSH_SERVER_COMMAND,
+ text: &mosh,
+ rect: rect(
+ x + pad,
+ fy + line_h + ctx.px(LABEL_GAP),
+ inner,
+ ctx.px(INPUT_H),
+ ),
+ focused,
selected_all: false,
- action: SshViewAction::FocusOptionKey(index),
+ action: SshViewAction::FocusField(FIELD_MOSH_SERVER),
},
- key_caret,
+ caret,
)?;
- self.resolve_pending_caret_click(
- ctx,
- font,
- Focus::OptionValue(index),
- &value.text(),
- value_x + ctx.px(12.0),
- );
- let value_caret = self.caret_for(Focus::OptionValue(index));
- draw_text_input(
+ }
+ y += session_h + card_gap;
+
+ // ---- Advanced: raw ssh_config overrides.
+ let disclosure = if advanced_open { "▾" } else { "▸" };
+ let advanced_h = line_h + ctx.px(14.0);
+ self.widgets.push(
+ rect(x, y, w, advanced_h),
+ WidgetKind::Button,
+ SshViewAction::ToggleAdvanced,
+ );
+ ctx.draw_text(
+ &mut body_layers,
+ font,
+ x,
+ y + ((advanced_h - line_h) / 2.0).max(0.0),
+ &format!("{disclosure} {}", crate::i18n::tr("ssh-advanced")),
+ palette.secondary_text,
+ w,
+ )?;
+ y += advanced_h + ctx.px(8.0);
+
+ if advanced_open {
+ let remove_w = ctx.px(INPUT_H);
+ let row_gap = ctx.px(8.0);
+ let pair_w = (w - remove_w - row_gap * 2.0).max(0.0);
+ let key_w = pair_w * 0.42;
+ let value_w = pair_w - key_w;
+ for (index, (key, value)) in options.iter().enumerate() {
+ let key_x = x;
+ let value_x = key_x + key_w + row_gap;
+ let text_pad = ctx.px(12.0);
+ self.resolve_pending_caret_click(
+ ctx,
+ font,
+ Focus::OptionKey(index),
+ &key.text(),
+ key_x + text_pad,
+ );
+ let key_caret = self.caret_for(Focus::OptionKey(index));
+ let key_focused = self.focus == Focus::OptionKey(index);
+ draw_text_input(
+ ctx,
+ &mut body_layers,
+ font,
+ &mut self.widgets,
+ &self.interaction,
+ palette,
+ tokens,
+ text_pad,
+ cursor_on,
+ TextInputSpec {
+ placeholder: "ProxyJump",
+ text: &key.text(),
+ rect: rect(key_x, y, key_w, ctx.px(INPUT_H)),
+ focused: key_focused,
+ selected_all: false,
+ action: SshViewAction::FocusOptionKey(index),
+ },
+ key_caret,
+ )?;
+ self.resolve_pending_caret_click(
+ ctx,
+ font,
+ Focus::OptionValue(index),
+ &value.text(),
+ value_x + text_pad,
+ );
+ let value_caret = self.caret_for(Focus::OptionValue(index));
+ let value_focused = self.focus == Focus::OptionValue(index);
+ draw_text_input(
+ ctx,
+ &mut body_layers,
+ font,
+ &mut self.widgets,
+ &self.interaction,
+ palette,
+ tokens,
+ text_pad,
+ cursor_on,
+ TextInputSpec {
+ placeholder: "user@bastion",
+ text: &value.text(),
+ rect: rect(value_x, y, value_w, ctx.px(INPUT_H)),
+ focused: value_focused,
+ selected_all: false,
+ action: SshViewAction::FocusOptionValue(index),
+ },
+ value_caret,
+ )?;
+ draw_icon_button(
+ ctx,
+ &mut body_layers,
+ &mut self.widgets,
+ &self.interaction,
+ palette,
+ value_x + value_w + row_gap,
+ y,
+ remove_w,
+ SvgIcon::Trash2,
+ SshViewAction::RemoveOption(index),
+ )?;
+ y += ctx.px(INPUT_H) + row_gap;
+ }
+
+ let add_label = crate::i18n::tr("ssh-add-option");
+ let add_w = ctx.measure_text_width(font, &add_label) + ctx.px(56.0);
+ let add_state = self.button_state(SshViewAction::AddOption);
+ draw_button(
ctx,
- layers,
+ &mut body_layers,
font,
&mut self.widgets,
- &self.interaction,
palette,
- tokens,
- ctx.px(12.0),
- cursor_on,
- TextInputSpec {
- placeholder: "user@bastion",
- text: &value.text(),
- rect: rect(value_x, cur_y, value_w, ctx.px(INPUT_H)),
- focused: focus == Focus::OptionValue(index),
- selected_all: false,
- action: SshViewAction::FocusOptionValue(index),
+ ButtonSpec {
+ label: &add_label,
+ action: SshViewAction::AddOption,
+ rect: rect(x, y, add_w, ctx.px(BTN_H)),
+ state: add_state,
+ kind: WidgetKind::Button,
+ variant: ButtonVariant::Secondary,
},
- value_caret,
)?;
- draw_icon_button(
+ y += ctx.px(BTN_H) + ctx.px(18.0);
+ }
+
+ if let Some(err) = &error {
+ ctx.draw_text(
+ &mut body_layers,
+ font,
+ x,
+ y,
+ &format!("⚠ {err}"),
+ palette.danger,
+ w,
+ )?;
+ y += line_h + ctx.px(12.0);
+ }
+
+ // ---- footer. Creating a host offers "Save & Open" as the primary
+ // action, since there is no Connect button above yet.
+ let button_gap = ctx.px(10.0);
+ let mut buttons: Vec<(String, SshViewAction, ButtonVariant)> = Vec::new();
+ if editing.is_none() {
+ buttons.push((
+ crate::i18n::tr("ssh-save-open"),
+ SshViewAction::SaveAndConnect,
+ ButtonVariant::Primary,
+ ));
+ buttons.push((
+ crate::i18n::tr("ssh-save"),
+ SshViewAction::Save,
+ ButtonVariant::Secondary,
+ ));
+ } else {
+ buttons.push((
+ crate::i18n::tr("ssh-save"),
+ SshViewAction::Save,
+ ButtonVariant::Primary,
+ ));
+ }
+ buttons.push((
+ crate::i18n::tr("ssh-cancel"),
+ SshViewAction::Cancel,
+ ButtonVariant::Secondary,
+ ));
+ // The column is narrow and fixed. Rather than squeeze the labels
+ // until they ellipsize -- which is how a button stops saying what it
+ // does -- lay them out at their natural width while they fit, and
+ // stack them full-width when they do not.
+ let natural: Vec<f32> = buttons
+ .iter()
+ .map(|(label, _, _)| ctx.measure_text_width(font, label) + ctx.px(56.0))
+ .collect();
+ let row_fits = natural.iter().sum::<f32>()
+ + button_gap * buttons.len().saturating_sub(1) as f32
+ <= w;
+ let mut bx = x;
+ for ((label, action, variant), natural_w) in buttons.iter().zip(natural.iter()) {
+ let each = if row_fits { *natural_w } else { w };
+ let state = self.button_state(*action);
+ draw_button(
ctx,
- layers,
+ &mut body_layers,
+ font,
&mut self.widgets,
- &self.interaction,
palette,
- value_x + value_w + gap,
- cur_y,
- remove_w,
- SvgIcon::Trash2,
- SshViewAction::RemoveOption(index),
+ ButtonSpec {
+ label,
+ action: *action,
+ rect: rect(bx, y, each, ctx.px(BTN_H)),
+ state,
+ kind: WidgetKind::Button,
+ variant: *variant,
+ },
)?;
- cur_y += ctx.px(INPUT_H) + gap;
+ if row_fits {
+ bx += each + button_gap;
+ } else {
+ y += ctx.px(BTN_H) + ctx.px(8.0);
+ }
}
-
- let add_label = crate::i18n::tr("ssh-add-option");
- let add_w = ctx.measure_text_width(font, &add_label) + ctx.px(36.0);
- // Resolved before `self.widgets` is borrowed mutably below.
- let add_state = self.button_state(SshViewAction::AddOption, false);
- draw_button(
+ // A stacked column already advanced past its last button.
+ if row_fits {
+ y += ctx.px(BTN_H);
+ }
+ y += ctx.px(PAD);
+ }
+ self.form_content_h = y - top;
+ let clip = QuadClipRect::from_top_left_pixels(
+ area.origin.x,
+ body_top,
+ area.max_x(),
+ area.max_y(),
+ &ctx.dimensions,
+ );
+ self.widgets.clip_since(
+ body_widgets_start,
+ rect(area.origin.x, body_top, area.size.width, body_height),
+ );
+ heap.apply_to_clipped(layers, clip, 1.0)?;
+
+ // The header sits above the clip, so the band it occupies is simply
+ // never drawn into by the body -- no mask needed.
+ let mut hy = area.origin.y;
+ title_ctx.draw_text_on_layer(layers, 2, title_font, x, hy, &heading, palette.text, w)?;
+ hy += title_h + ctx.px(4.0);
+ if let Some(endpoint) = endpoint {
+ ctx.draw_text_on_layer(layers, 2, font, x, hy, &endpoint, palette.muted_text, w)?;
+ hy += line_h;
+ }
+ hy += ctx.px(14.0);
+ if connect {
+ let label = crate::i18n::tr("ssh-connect");
+ let state = self.button_state(SshViewAction::Connect);
+ draw_button_on_layer(
ctx,
layers,
font,
&mut self.widgets,
palette,
ButtonSpec {
- label: &add_label,
- action: SshViewAction::AddOption,
- rect: rect(x, cur_y, add_w, ctx.px(BTN_H)),
- state: add_state,
+ label: &label,
+ action: SshViewAction::Connect,
+ rect: rect(x, hy, w, ctx.px(BTN_H)),
+ state,
kind: WidgetKind::Button,
+ variant: ButtonVariant::Primary,
},
- )?;
- cur_y += ctx.px(BTN_H) + ctx.px(24.0);
- }
-
- if let Some(err) = &error {
- ctx.draw_text(
- layers,
- font,
- x,
- cur_y,
- &format!("⚠ {err}"),
- palette.text,
- field_w,
- )?;
- cur_y += line_h + ctx.px(12.0);
- }
-
- // Buttons sized to their (measured) label so nothing is truncated.
- let gap = ctx.px(12.0);
- let btn_w = |label: &str| ctx.measure_text_width(font, label) + ctx.px(36.0);
- let mut bx = x;
- for (label, action, primary) in [
- (
- crate::i18n::tr("ssh-save-open"),
- SshViewAction::SaveAndConnect,
- true,
- ),
- (crate::i18n::tr("ssh-save"), SshViewAction::Save, false),
- (crate::i18n::tr("ssh-cancel"), SshViewAction::Cancel, false),
- ] {
- let w = btn_w(&label);
- let spec = ButtonSpec {
- label: &label,
- action,
- rect: rect(bx, cur_y, w, ctx.px(BTN_H)),
- state: self.button_state(action, primary),
- kind: WidgetKind::Button,
- };
- draw_button(ctx, layers, font, &mut self.widgets, palette, spec)?;
- bx += w + gap;
- }
- cur_y += ctx.px(BTN_H) + ctx.px(PAD);
-
- self.form_content_h = cur_y - top;
- // These draws cannot clip, so hide anything that scrolled above the
- // column by repainting the strip over it (still inside our own area).
- if self.form_scroll.offset > 0.0 {
- ctx.draw_rect(
- layers,
2,
- x,
- y - ctx.px(PAD),
- field_w,
- ctx.px(PAD),
- palette.window_bg,
- )?;
- }
- if self.form_scroll.has_overflow() {
- draw_scrollbar(
- ctx,
- layers,
- palette,
- tokens,
- self.form_area,
- self.form_scroll,
)?;
}
+
+ // No scrollbar and no edge fades here: a fixed-width column of three
+ // cards is short enough that a thumb is mostly clutter, and a fade
+ // over the clipped edge dimmed the Save/Cancel row into looking
+ // broken. Content past the fold is simply clipped.
Ok(())
}
- fn button_state(&self, action: SshViewAction, primary: bool) -> ControlState {
+ /// Which of the three visual states a button is in. "Primary" is no
+ /// longer one of them: that is the button's `variant`, and it is
+ /// orthogonal to whether the pointer happens to be over it.
+ fn button_state(&self, action: SshViewAction) -> ControlState {
if self.interaction.pressed == Some(action) {
ControlState::Pressed
} else if self.interaction.hovered == Some(action) {
ControlState::Hovered
- } else if primary {
- ControlState::Active
} else {
ControlState::Normal
}
@@ -2169,11 +2721,28 @@ impl ContentView for SshHostsView {
area: RectF,
palette: UiPalette,
font: &Rc<LoadedFont>,
- _title_font: &Rc<LoadedFont>,
- _section_font: &Rc<LoadedFont>,
+ title_font: &Rc<LoadedFont>,
+ section_font: &Rc<LoadedFont>,
cursor_on: bool,
) -> anyhow::Result<()> {
- self.paint_impl(ctx, layers, area, palette, font, cursor_on)
+ self.paint_impl(
+ ctx,
+ layers,
+ area,
+ palette,
+ font,
+ title_font,
+ section_font,
+ cursor_on,
+ )
+ }
+
+ fn run_remote_host_command(
+ &mut self,
+ host_id: &str,
+ command: RemoteHostCommand,
+ ) -> ContentViewResponse {
+ self.run_host_command(host_id, command)
}
fn on_mouse(&mut self, x: f32, y: f32, kind: WMEK) -> ContentViewResponse {
@@ -2188,6 +2757,11 @@ impl ContentView for SshHostsView {
self.on_paste_impl(text)
}
+ fn begin_new_remote_host(&mut self) {
+ // Same reset the `+` button performs; the list refreshes on paint.
+ self.open_new_form();
+ }
+
fn copy_text(&self) -> Option<String> {
let input = self.focused_input()?;
let text = input
@@ -2205,8 +2779,55 @@ impl ContentView for SshHostsView {
mod tests {
use super::{
focus_after_collapsing_advanced, ssh_options_from_rows, tab_stops_for, text_input_with,
- Focus, HostForm, BASE_FIELD_COUNT, FIELD_HOST, FIELD_WORKSPACE,
+ ContentViewResponse, Focus, HostForm, RemoteHostCommand, SshHostsView, BASE_FIELD_COUNT,
+ FIELD_HOST, FIELD_NAME, FIELD_PORT, FIELD_USER, FIELD_WORKSPACE,
};
+ use crate::ssh_hosts::{SshHostEntry, SshHostSource, SshHostSpec};
+
+ fn spec(label: &str, host: &str) -> SshHostSpec {
+ SshHostSpec {
+ label: label.to_string(),
+ host: host.to_string(),
+ port: Some(2222),
+ username: Some("deploy".to_string()),
+ identity_file: Some("~/.ssh/id_ed25519".to_string()),
+ password: None,
+ ssh_options: Default::default(),
+ multiplexing: false,
+ default_workspace: None,
+ detect_os: true,
+ detected_distro: None,
+ use_mosh: false,
+ mosh_server_command: super::ssh_hosts::DEFAULT_MOSH_SERVER_COMMAND.to_string(),
+ }
+ }
+
+ #[test]
+ fn duplicate_opens_a_prefilled_new_host_form() {
+ let mut view = SshHostsView::new();
+ view.filtered = vec![SshHostEntry {
+ id: "ssh-original".to_string(),
+ source: SshHostSource::ThinkTerm,
+ spec: spec("prod-1", "10.0.0.7"),
+ }];
+
+ let response = view.run_host_command("ssh-original", RemoteHostCommand::Duplicate);
+ assert!(matches!(response, ContentViewResponse::Redraw));
+
+ let form = view
+ .form
+ .as_ref()
+ .expect("Duplicate opens the new-host form; it does not save a record on its own");
+ assert!(form.editing.is_none(), "a duplicate is a new host, not an edit");
+ assert_eq!(form.fields[FIELD_NAME].text(), "prod-1 copy");
+ assert_eq!(form.fields[FIELD_PORT].text(), "2222");
+ assert_eq!(form.fields[FIELD_USER].text(), "deploy");
+ // A record is keyed by `user@host:port`, so a copy carrying the
+ // original's host could never be saved -- it would collide with the
+ // host it was copied from. Host is the one field left for the user.
+ assert_eq!(form.fields[FIELD_HOST].text(), "");
+ assert_eq!(view.focus, Focus::Field(FIELD_HOST));
+ }
fn row(key: &str, value: &str) -> (super::TextInputState, super::TextInputState) {
(
diff --git a/wezterm-gui/src/termwindow/ui/command_palette.rs b/wezterm-gui/src/termwindow/ui/command_palette.rs
index 82c12aec..6057605d 100644
--- a/wezterm-gui/src/termwindow/ui/command_palette.rs
+++ b/wezterm-gui/src/termwindow/ui/command_palette.rs
@@ -709,6 +709,7 @@ fn nerd_icon_to_svg(name: Option<&str>) -> Option<SvgIcon> {
"md_content_paste" => SvgIcon::ClipboardPaste,
"md_delete" => SvgIcon::Trash2,
"md_drag" => SvgIcon::ArrowRight,
+ "md_earth" => SvgIcon::Globe,
"md_edit" => SvgIcon::Pencil,
"md_folder_open" => SvgIcon::FolderOpen,
"md_format_align_bottom" => SvgIcon::ArrowDown,
@@ -725,6 +726,7 @@ fn nerd_icon_to_svg(name: Option<&str>) -> Option<SvgIcon> {
"md_server_network" => SvgIcon::Server,
"md_sticker_emoji" => SvgIcon::MessageCircle,
"md_tab_plus" => SvgIcon::Plus,
+ "md_update" => SvgIcon::RefreshCw,
"md_window_minimize" => SvgIcon::Minimize2,
"md_window_restore" => SvgIcon::Maximize2,
"oct_browser" => SvgIcon::Globe,
diff --git a/wezterm-gui/src/termwindow/ui/context_menu.rs b/wezterm-gui/src/termwindow/ui/context_menu.rs
index ce8180e3..7184b5be 100644
--- a/wezterm-gui/src/termwindow/ui/context_menu.rs
+++ b/wezterm-gui/src/termwindow/ui/context_menu.rs
@@ -230,6 +230,18 @@ impl crate::TermWindow {
crate::termwindow::ContextMenuApplicationAction::SetFrontendAccessMode(mode) => {
self.request_frontend_access_mode(mode);
}
+ crate::termwindow::ContextMenuApplicationAction::RemoteHost { host_id, command } => {
+ let key = crate::termwindow::ssh_hosts_view::SSH_HOSTS_CONTENT_VIEW_KEY;
+ let Some(id) = self.content_view_id_for_key(key) else {
+ return;
+ };
+ let response = self
+ .content_view_mut_by_id(id)
+ .map(|view| view.run_remote_host_command(&host_id, command));
+ if let Some(response) = response {
+ self.handle_content_response_for(id, response);
+ }
+ }
crate::termwindow::ContextMenuApplicationAction::ActivateWorkspaceThread {
space_id,
thread_id,
@@ -1115,6 +1127,7 @@ fn menu_icon(icon: &ContextMenuIcon) -> Option<SvgIcon> {
ContextMenuIcon::Home => Some(SvgIcon::House),
ContextMenuIcon::Info => Some(SvgIcon::Info),
ContextMenuIcon::MoveRight => Some(SvgIcon::ArrowRight),
+ ContextMenuIcon::Network => Some(SvgIcon::Globe),
ContextMenuIcon::New => Some(SvgIcon::Plus),
ContextMenuIcon::Note => Some(SvgIcon::NotebookTabs),
ContextMenuIcon::Notification => Some(SvgIcon::Bell),
diff --git a/window/src/lib.rs b/window/src/lib.rs
index a6e779d6..a380405a 100644
--- a/window/src/lib.rs
+++ b/window/src/lib.rs
@@ -233,6 +233,7 @@ pub enum ContextMenuIcon {
Info,
MoveLeft,
MoveRight,
+ Network,
New,
Note,
Notification,
@@ -313,6 +314,8 @@ impl ContextMenuIcon {
Self::Info => "info.circle",
Self::MoveLeft => "arrow.left",
Self::MoveRight => "arrow.right",
+ // The Mac glyph for "a machine somewhere else on the network".
+ Self::Network => "network",
Self::New => "plus",
Self::Note => "square.and.pencil",
Self::Notification => "bell",
@@ -369,6 +372,9 @@ impl ContextMenuIcon {
Self::Home => include_bytes!("../../third_party/lucide/icons/house.svg"),
Self::Info => include_bytes!("../../third_party/lucide/icons/info.svg"),
Self::MoveRight => include_bytes!("../../third_party/lucide/icons/arrow-right.svg"),
+ // lucide's meridian globe, the closest match to SF's `network`;
+ // `earth.svg` draws continents and reads as a different idea.
+ Self::Network => include_bytes!("../../third_party/lucide/icons/globe.svg"),
Self::New => include_bytes!("../../third_party/lucide/icons/plus.svg"),
Self::Note => include_bytes!("../../third_party/lucide/icons/notebook-tabs.svg"),
Self::Notification => include_bytes!("../../third_party/lucide/icons/bell.svg"),