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.

feat(hover): redesign hover tags and agent cards

RoversX3ae323d2f30a
diff --git a/thinkterm-i18n/i18n/de-DE.ftl b/thinkterm-i18n/i18n/de-DE.ftl
index 4e2017ff..dbf90b48 100644
--- a/thinkterm-i18n/i18n/de-DE.ftl
+++ b/thinkterm-i18n/i18n/de-DE.ftl
@@ -729,6 +729,19 @@ right-agents-state-done = Fertig
right-agents-none = Keine Agents erkannt
right-agents-group-other = Sonstige
right-agents-all-hidden = Alle Agents sind durch die Ansichtsoptionen ausgeblendet
+hover-card-agents = { $count ->
+ [one] 1 Agent
+ *[other] { $count } Agents
+}
+hover-card-thread = Thread
+hover-card-machine = Rechner
+hover-card-duration = Seit
+hover-card-subtasks = Teilaufgaben
+hover-card-more-agents = { $count } weitere
+hover-card-under-a-minute = unter einer Minute
+hover-card-minutes = { $count } Min.
+hover-card-hours = { $count } Std.
+hover-card-days = { $count } T.
right-agents-detection-off = Agent-Erkennung ist aus — Einstellungen öffnen
right-agents-count-working = { $count } arbeiten
right-agents-count-blocked = { $count ->
diff --git a/thinkterm-i18n/i18n/en-US.ftl b/thinkterm-i18n/i18n/en-US.ftl
index c9d7c9b8..7aa8fcab 100644
--- a/thinkterm-i18n/i18n/en-US.ftl
+++ b/thinkterm-i18n/i18n/en-US.ftl
@@ -729,6 +729,19 @@ right-agents-state-done = Done
right-agents-none = No agents detected
right-agents-group-other = Other
right-agents-all-hidden = Every agent is hidden by the view options
+hover-card-agents = { $count ->
+ [one] 1 agent
+ *[other] { $count } agents
+}
+hover-card-thread = Thread
+hover-card-machine = Machine
+hover-card-duration = For
+hover-card-subtasks = Sub-tasks
+hover-card-more-agents = { $count } more
+hover-card-under-a-minute = under a minute
+hover-card-minutes = { $count } min
+hover-card-hours = { $count } h
+hover-card-days = { $count } d
right-agents-detection-off = Agent detection is off — open settings
right-agents-count-working = { $count } working
right-agents-count-blocked = { $count ->
diff --git a/thinkterm-i18n/i18n/fr-FR.ftl b/thinkterm-i18n/i18n/fr-FR.ftl
index eddaafe1..4bb503f8 100644
--- a/thinkterm-i18n/i18n/fr-FR.ftl
+++ b/thinkterm-i18n/i18n/fr-FR.ftl
@@ -729,6 +729,19 @@ right-agents-state-done = Terminé
right-agents-none = Aucun agent détecté
right-agents-group-other = Autres
right-agents-all-hidden = Tous les agents sont masqués par les options d’affichage
+hover-card-agents = { $count ->
+ [one] 1 agent
+ *[other] { $count } agents
+}
+hover-card-thread = Session
+hover-card-machine = Machine
+hover-card-duration = Depuis
+hover-card-subtasks = Sous-tâches
+hover-card-more-agents = { $count } de plus
+hover-card-under-a-minute = moins d'une minute
+hover-card-minutes = { $count } min
+hover-card-hours = { $count } h
+hover-card-days = { $count } j
right-agents-detection-off = Détection des agents désactivée — ouvrir les réglages
right-agents-count-working = { $count } en cours
right-agents-count-blocked = { $count } en attente
diff --git a/thinkterm-i18n/i18n/ja-JP.ftl b/thinkterm-i18n/i18n/ja-JP.ftl
index ca476b4d..2a51dbd8 100644
--- a/thinkterm-i18n/i18n/ja-JP.ftl
+++ b/thinkterm-i18n/i18n/ja-JP.ftl
@@ -711,6 +711,16 @@ right-agents-state-done = 完了
right-agents-none = エージェントは検出されていません
right-agents-group-other = その他
right-agents-all-hidden = 表示オプションですべてのエージェントが非表示です
+hover-card-agents = { $count } 個のエージェント
+hover-card-thread = セッション
+hover-card-machine = マシン
+hover-card-duration = 経過
+hover-card-subtasks = サブタスク
+hover-card-more-agents = ほか { $count } 件
+hover-card-under-a-minute = 1 分未満
+hover-card-minutes = { $count } 分
+hover-card-hours = { $count } 時間
+hover-card-days = { $count } 日
right-agents-detection-off = エージェント検出はオフです — 設定を開く
right-agents-count-working = { $count } 件が作業中
right-agents-count-blocked = { $count } 件が入力待ち
diff --git a/thinkterm-i18n/i18n/zh-CN.ftl b/thinkterm-i18n/i18n/zh-CN.ftl
index 3f3402fd..7a84501a 100644
--- a/thinkterm-i18n/i18n/zh-CN.ftl
+++ b/thinkterm-i18n/i18n/zh-CN.ftl
@@ -711,6 +711,16 @@ right-agents-state-done = 已完成
right-agents-none = 未检测到 Agent
right-agents-group-other = 其他
right-agents-all-hidden = 显示选项隐藏了所有 Agent
+hover-card-agents = { $count } 个 Agent
+hover-card-thread = 会话
+hover-card-machine = 机器
+hover-card-duration = 持续
+hover-card-subtasks = 子任务
+hover-card-more-agents = 还有 { $count } 个
+hover-card-under-a-minute = 不到 1 分钟
+hover-card-minutes = { $count } 分钟
+hover-card-hours = { $count } 小时
+hover-card-days = { $count } 天
right-agents-detection-off = Agent 检测已关闭 — 打开设置
right-agents-count-working = { $count } 个运行中
right-agents-count-blocked = { $count } 个等待输入
diff --git a/wezterm-gui/src/agent_status/mod.rs b/wezterm-gui/src/agent_status/mod.rs
index c56d3f78..9638a422 100644
--- a/wezterm-gui/src/agent_status/mod.rs
+++ b/wezterm-gui/src/agent_status/mod.rs
@@ -156,8 +156,10 @@ pub(crate) fn list_agent_panes() -> Vec<AgentPaneStatus> {
}
/// The snapshot behind [`list_agent_panes`], shared rather than copied:
-/// for the callers that only look.
-fn agent_panes() -> std::sync::Arc<Vec<AgentPaneStatus>> {
+/// for the callers that only look. A new one replaces it on every status
+/// change and otherwise every [`AGENT_PANES_TTL`], so while it is the same
+/// `Arc` nothing in it has changed.
+pub(crate) fn agent_panes() -> std::sync::Arc<Vec<AgentPaneStatus>> {
if let Ok(guard) = AGENT_PANES_CACHE.lock() {
if let Some((at, cached)) = guard.as_ref() {
if at.elapsed() < AGENT_PANES_TTL {
@@ -306,20 +308,45 @@ impl AgentPaneStatus {
/// the reason the bell, a card and a notification give -- shaped by the
/// user's choice of what to show. `None` when there is nothing to say.
pub(crate) fn reason_line(agent: &AgentPaneStatus) -> Option<String> {
- let report = agent.report.as_ref()?;
- let show = crate::native_settings::agent_status_display();
- let kind = report
- .kind
- .filter(|_| show.reason)
- .map(|kind| crate::i18n::tr(blocked_kind_key(kind)));
- let msg = report.msg.clone().filter(|_| show.description);
+ let (kind, msg) = report_said(agent, crate::native_settings::agent_status_display());
+ let kind = kind.map(|kind| crate::i18n::tr(blocked_kind_key(kind)));
match (kind, msg) {
(Some(kind), Some(msg)) => Some(format!("{kind} · {msg}")),
- (Some(text), None) | (None, Some(text)) => Some(text),
+ (Some(kind), None) => Some(kind),
+ (None, Some(msg)) => Some(msg.to_string()),
(None, None) => None,
}
}
+/// How far an agent's report says it has got, when the user chose to see it.
+pub(crate) fn report_progress(
+ agent: &AgentPaneStatus,
+ show: crate::native_settings::NativeAgentStatusDisplay,
+) -> Option<u8> {
+ agent
+ .report
+ .as_ref()
+ .and_then(|report| report.progress)
+ .filter(|_| show.progress)
+}
+
+/// What an agent's report says, as far as the user chose to see it: why it
+/// waits, and what it is doing.
+pub(crate) fn report_said(
+ agent: &AgentPaneStatus,
+ show: crate::native_settings::NativeAgentStatusDisplay,
+) -> (Option<ProgramBlockedKind>, Option<&str>) {
+ let report = agent.report.as_ref();
+ (
+ report
+ .and_then(|report| report.kind)
+ .filter(|_| show.reason),
+ report
+ .and_then(|report| report.msg.as_deref())
+ .filter(|_| show.description),
+ )
+}
+
/// Why a thread wants a look, in its most pressing program's own words --
/// an error before a wait before a finished result. For the bell's list and
/// the system notification; `None` when no program in it said anything.
diff --git a/wezterm-gui/src/termwindow/keyevent.rs b/wezterm-gui/src/termwindow/keyevent.rs
index 99a0c3de..548574ac 100644
--- a/wezterm-gui/src/termwindow/keyevent.rs
+++ b/wezterm-gui/src/termwindow/keyevent.rs
@@ -822,6 +822,10 @@ impl super::TermWindow {
}
pub fn raw_key_event_impl(&mut self, key: RawKeyEvent, context: &dyn WindowOps) {
+ // Typing puts away a hover card that would cover what is typed.
+ if key.key_is_down && !key.key.is_modifier() && self.dismiss_hover_tooltip() {
+ context.invalidate();
+ }
let mut input_trace =
crate::input_diagnostics::KeyEventTrace::begin(key.key_is_down, key.key.is_modifier());
// The leader key is a kind of modal modifier key.
diff --git a/wezterm-gui/src/termwindow/mod.rs b/wezterm-gui/src/termwindow/mod.rs
index 43db39af..113ede23 100644
--- a/wezterm-gui/src/termwindow/mod.rs
+++ b/wezterm-gui/src/termwindow/mod.rs
@@ -1931,6 +1931,34 @@ pub const TOOLTIP_DELAY: Duration = Duration::from_millis(500);
pub struct HoverTooltip {
pub item: UIItem,
pub since: Instant,
+ /// Shown at once, with no pause: another surface was up a moment ago,
+ /// and someone moving from one to the next is reading them, as the Mac
+ /// does it.
+ pub warm: bool,
+ /// The keyboard shortcut for what the item does, looked up once when
+ /// the hover starts.
+ pub shortcut: Option<String>,
+ /// Its last paint found nothing to show -- no agents left, no label, or
+ /// the item gone -- so it keeps nothing warm for the next one.
+ pub blank: bool,
+ /// An agent card's machine fact -- `None` inside when unknown: read from
+ /// the host list the first time the card paints, and gone with the hover.
+ pub machine: Option<Option<String>>,
+ /// A click or a key went in while it was up: nothing shows again until
+ /// the pointer moves on to something else.
+ pub dismissed: bool,
+}
+
+/// How long after a hover surface goes that the next one still shows at
+/// once.
+pub const TOOLTIP_WARM: Duration = Duration::from_millis(800);
+
+impl HoverTooltip {
+ /// Whether it is showing: past its delay, or warm, and neither blank
+ /// nor dismissed.
+ pub fn visible(&self) -> bool {
+ !self.blank && !self.dismissed && (self.warm || self.since.elapsed() >= TOOLTIP_DELAY)
+ }
}
/// Where a hover tag's left edge goes, given the rect it names.
@@ -2038,6 +2066,17 @@ pub(crate) fn thread_has_card(item_type: &UIItemType) -> bool {
})
}
+/// The action a tagged button runs, so its tag can show the shortcut.
+pub fn tooltip_action_for(item_type: &UIItemType) -> Option<KeyAssignment> {
+ Some(match item_type {
+ UIItemType::WorkspaceSidebarSettings => KeyAssignment::OpenSettings,
+ UIItemType::WorkspaceSidebarThreadSearch => KeyAssignment::OpenThreadSearch,
+ UIItemType::WorkspaceSidebarSshHosts => KeyAssignment::OpenSshHosts,
+ UIItemType::WorkspaceSidebarLiveOverview => KeyAssignment::ToggleLiveOverview,
+ _ => return None,
+ })
+}
+
/// The tag to show for an item whose own text cannot say enough: an icon-only
/// button (no text at all) or a row whose label is cut to fit the sidebar.
/// `None` for everything that already reads in full.
@@ -2074,6 +2113,9 @@ pub fn tooltip_label_for(item_type: &UIItemType) -> Option<String> {
UIItemType::WorkspaceSidebarSshHosts => "tooltip-sidebar-ssh-hosts",
UIItemType::WorkspaceSidebarLiveOverview => "tooltip-sidebar-live-overview",
UIItemType::WorkspaceSidebarNotifications => "tooltip-sidebar-notifications",
+ UIItemType::RightSidebarAgent(crate::agent_status::AgentPanelAction::ViewOptions) => {
+ "tooltip-sidebar-view-options"
+ }
_ => return None,
};
Some(crate::i18n::tr(key))
@@ -2829,10 +2871,14 @@ pub struct TermWindow {
pub right_status: String,
pub left_status: String,
last_ui_item: Option<UIItem>,
- /// The icon-only button the pointer is resting on, and when it arrived.
- /// The tag is only painted once it has been there for TOOLTIP_DELAY, so
- /// that sweeping the pointer across the sidebar does not strobe labels.
+ /// The item with a hover surface the pointer is resting on, and when it
+ /// arrived. The surface is only painted once it has been there for
+ /// TOOLTIP_DELAY, so that sweeping the pointer across the sidebar does
+ /// not strobe labels -- unless another one was up a moment before.
hover_tooltip: Option<HoverTooltip>,
+ /// Until when a new hover surface shows at once: one was up until just
+ /// before.
+ hover_tooltip_warm_until: Option<Instant>,
/// Tracks whether the current mouse-down event is part of click-focus.
/// If so, we ignore mouse events until released
is_click_to_focus_window: bool,
@@ -4880,6 +4926,7 @@ impl TermWindow {
right_sidebar_input_layouts: Vec::new(),
last_ui_item: None,
hover_tooltip: None,
+ hover_tooltip_warm_until: None,
is_click_to_focus_window: false,
key_table_state: KeyTableState::default(),
modal: RefCell::new(None),
diff --git a/wezterm-gui/src/termwindow/mouseevent.rs b/wezterm-gui/src/termwindow/mouseevent.rs
index ee7436df..24d35d8e 100644
--- a/wezterm-gui/src/termwindow/mouseevent.rs
+++ b/wezterm-gui/src/termwindow/mouseevent.rs
@@ -1684,7 +1684,8 @@ impl super::TermWindow {
///
/// Keyed by item *type*, not by the UIItem: the sidebar rebuilds its items
/// every frame and a button's rect can shift by a pixel, which must not
- /// restart the delay and leave the tag forever one frame away.
+ /// restart the delay and leave the tag forever one frame away. An Agents
+ /// panel row and its sub-task line count as one.
///
/// Only records when the pointer arrived. The wakeup that makes the tag
/// appear is registered by `paint_hover_tooltip`, because `paint_impl`
@@ -1694,27 +1695,67 @@ impl super::TermWindow {
.filter(|item| {
crate::termwindow::tooltip_label_for(&item.item_type).is_some()
|| crate::termwindow::thread_has_card(&item.item_type)
+ || crate::termwindow::render::hover::agent_card_pane(&item.item_type).is_some()
})
// The dynamic half of the rule: no tag over a live rename
// editor, and none for a file row whose label already reads in
// full. `paint_hover_tooltip` re-checks the same predicate.
.filter(|item| self.hover_tooltip_allowed(&item.item_type));
+ // A surface that was showing keeps the next one warm for a moment.
+ let was_visible = self
+ .hover_tooltip
+ .as_ref()
+ .is_some_and(|hover| hover.visible());
match labelled {
- None => self.hover_tooltip = None,
+ None => {
+ if was_visible {
+ self.hover_tooltip_warm_until =
+ Some(Instant::now() + crate::termwindow::TOOLTIP_WARM);
+ }
+ self.hover_tooltip = None;
+ }
Some(item) => match self.hover_tooltip.as_mut() {
- Some(hover) if hover.item.item_type == item.item_type => {
+ Some(hover)
+ if crate::termwindow::render::hover::same_hover_target(
+ &hover.item.item_type,
+ &item.item_type,
+ ) =>
+ {
hover.item = item.clone();
}
_ => {
+ let warm = was_visible
+ || self
+ .hover_tooltip_warm_until
+ .is_some_and(|until| Instant::now() < until);
+ let shortcut = self.hover_shortcut(&item.item_type);
self.hover_tooltip = Some(crate::termwindow::HoverTooltip {
item: item.clone(),
since: Instant::now(),
+ warm,
+ shortcut,
+ blank: false,
+ machine: None,
+ dismissed: false,
});
}
},
}
}
+ /// Puts away the hover surface the pointer rests on, as a click or a key
+ /// does; true when one was showing.
+ pub(crate) fn dismiss_hover_tooltip(&mut self) -> bool {
+ let Some(hover) = self.hover_tooltip.as_mut() else {
+ return false;
+ };
+ let was_visible = hover.visible();
+ hover.dismissed = true;
+ // Nor does the next one show at once: the user put this one away.
+ self.hover_tooltip_warm_until = None;
+ was_visible
+ }
+
fn enter_ui_item(&mut self, item: &UIItem) {
match item.item_type {
UIItemType::TabBar(_) | UIItemType::TerminalBar(_) => {}
@@ -2415,6 +2456,9 @@ impl super::TermWindow {
// Also clears while a drag holds the capture: a tag hovering next to
// the pointer mid-drag is noise.
self.update_hover_tooltip(ui_item.as_ref());
+ if matches!(event.kind, WMEK::Press(_)) && self.dismiss_hover_tooltip() {
+ context.invalidate();
+ }
// A press anywhere other than the row being renamed commits a pending
// inline rename (Enter semantics); otherwise the editor stays armed
@@ -2500,6 +2544,8 @@ impl super::TermWindow {
&& event.coords.y as usize <= self.dimensions.pixel_height
});
self.current_mouse_event = None;
+ // No hover surface outlives the pointer leaving the window.
+ self.update_hover_tooltip(None);
// The machine reads `Away` now: cancels an Arming, starts a grace.
self.update_workspace_sidebar_hover(context);
self.update_right_sidebar_hover(context);
diff --git a/wezterm-gui/src/termwindow/render/hover.rs b/wezterm-gui/src/termwindow/render/hover.rs
new file mode 100644
index 00000000..4cd5cf63
--- /dev/null
+++ b/wezterm-gui/src/termwindow/render/hover.rs
@@ -0,0 +1,1129 @@
+//! Hover surfaces: the tag an icon-only button or a cut-short row shows,
+//! and the cards a thread row and an Agents panel row show. One look for
+//! all of them, the right-click menu's: its card colours, a hairline border
+//! and the soft two-layer shadow. They appear after a pause; once one has
+//! shown, the next one shows at once, as on the Mac.
+//!
+//! Text goes through the sidebar's cached shaping, so a surface that stays
+//! up while a spinner repaints the window shapes nothing again. It wraps
+//! rather than being cut, and whatever still runs over fades, as in the
+//! Agents panel.
+
+use crate::agent_status::{self, AgentPaneStatus, AgentPanelAction, ShownState};
+use crate::quad::TripleLayerQuadAllocator;
+use crate::termwindow::ui::agent_panel::{
+ agent_row_title, agent_state_icon, agent_state_key, agent_title, brand_of, working_subtasks,
+ AGENT_PROGRESS_HEIGHT,
+};
+use crate::termwindow::{HoverTooltip, TermWindow, UIItem, UIItemType, TOOLTIP_DELAY};
+use crate::ui::{DrawContext, UiPalette};
+use crate::utilsprites::RenderMetrics;
+use anyhow::Context;
+use mux::pane::PaneId;
+use std::ops::Range;
+use std::rc::Rc;
+use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH};
+use wezterm_font::LoadedFont;
+use window::color::LinearRgba;
+use window::{Modifiers, UIKeyCapRendering};
+
+const TAG_RADIUS: f32 = 16.0;
+const CARD_RADIUS: f32 = 24.0;
+const TAG_PAD_X: f32 = 18.0;
+const TAG_PAD_Y: f32 = 10.0;
+const CARD_PAD_X: f32 = 28.0;
+const CARD_PAD_Y: f32 = 24.0;
+/// A tag's widest before it wraps, and the lines it wraps to.
+const TAG_MAX_WIDTH: f32 = 600.0;
+const TAG_LINES: usize = 3;
+const CARD_WIDTH: f32 = 560.0;
+/// Lines an agent card gives its title and its description.
+const CARD_TITLE_LINES: usize = 2;
+const CARD_MESSAGE_LINES: usize = 4;
+/// Between a surface and what it describes, and between a card's parts.
+const GAP: f32 = 16.0;
+/// Between a tag's label and its shortcut.
+const SHORTCUT_GAP: f32 = 14.0;
+/// A tag's shortcut against its label's size.
+const SHORTCUT_SCALE: f64 = 0.86;
+/// Between a card and the row it describes, clear of the sidebar's edge.
+const CARD_GAP: f32 = 22.0;
+/// Between two lines of wrapped text.
+const LINE_SPACING: f32 = 2.0;
+
+/// The fonts and colours every hover surface is set in.
+struct HoverStyle {
+ body: Rc<LoadedFont>,
+ strong: Rc<LoadedFont>,
+ metrics: RenderMetrics,
+ strong_metrics: RenderMetrics,
+ line: f32,
+ palette: UiPalette,
+ font_size: f64,
+}
+
+impl TermWindow {
+ /// The hover surface for whatever the pointer rests on, once it has
+ /// rested long enough.
+ pub(crate) fn paint_hover_tooltip(&mut self) -> anyhow::Result<()> {
+ let Some(hover) = self.hover_tooltip.clone().filter(|hover| !hover.dismissed) else {
+ return Ok(());
+ };
+ if !hover.warm {
+ let remaining = TOOLTIP_DELAY.saturating_sub(hover.since.elapsed());
+ if !remaining.is_zero() {
+ // Ask for the frame that will find the delay elapsed. This has
+ // to happen here and not where the pointer arrived: paint_impl
+ // clears has_animation on entry, so a deadline registered from
+ // the mouse handler is wiped before anything can read it.
+ self.update_next_frame_time(Some(Instant::now() + remaining));
+ return Ok(());
+ }
+ }
+ let painted = self.paint_hover(&hover)?;
+ if let Some(hover) = self.hover_tooltip.as_mut() {
+ hover.blank = !painted;
+ }
+ Ok(())
+ }
+
+ /// Paints `hover`'s surface; false when there turns out to be none.
+ fn paint_hover(&mut self, hover: &HoverTooltip) -> anyhow::Result<bool> {
+ // Re-check the dynamic conditions at paint time: a rename started
+ // from a key assignment (no mouse event) or a row whose label no
+ // longer overflows must suppress an already-armed tag.
+ if !self.hover_tooltip_allowed(&hover.item.item_type) {
+ return Ok(false);
+ }
+ let Some(item) = self.hover_anchor(&hover.item.item_type) else {
+ return Ok(false);
+ };
+ if let Some(pane_id) = agent_card_pane(&item.item_type) {
+ // Borrowed from the shared snapshot rather than copied each frame.
+ let snapshot = agent_status::agent_panes();
+ let Some(agent) = snapshot.iter().find(|agent| agent.pane_id == pane_id) else {
+ return Ok(false);
+ };
+ let style = self.hover_style()?;
+ self.paint_agent_hover_card(&item, agent, &style)?;
+ return Ok(true);
+ }
+ let agents = crate::termwindow::thread_card_agents(&item.item_type);
+ if !agents.is_empty() {
+ let style = self.hover_style()?;
+ self.paint_thread_hover_card(&item, &agents, &style)?;
+ return Ok(true);
+ }
+ let Some(label) = crate::termwindow::tooltip_label_for(&item.item_type) else {
+ return Ok(false);
+ };
+ let style = self.hover_style()?;
+ self.paint_hover_tag(&item, &label, hover.shortcut.as_deref(), &style)?;
+ Ok(true)
+ }
+
+ /// The item a surface sits beside, as this frame laid it out: none when
+ /// it is gone, with its sidebar hidden or its row scrolled away, and
+ /// none when it is no longer under the pointer -- a list that re-sorted
+ /// under a still pointer has put another row there. An agent card stays
+ /// beside the agent's row while the pointer is on the row's sub-task
+ /// line.
+ fn hover_anchor(&self, item_type: &UIItemType) -> Option<UIItem> {
+ let found = match agent_card_pane(item_type) {
+ Some(pane_id) => self
+ .ui_items
+ .iter()
+ .find(|item| agent_row_pane(&item.item_type) == Some(pane_id)),
+ None => self
+ .ui_items
+ .iter()
+ .find(|item| item.item_type == *item_type),
+ };
+ found
+ .filter(|item| self.is_pointer_over_ui_rect(item.x, item.y, item.width, item.height))
+ .cloned()
+ }
+
+ /// The shortcut a tag shows after its label: the first chord bound to
+ /// the item's action, the platform's own modifier first, as the
+ /// keyboard settings label it.
+ pub(crate) fn hover_shortcut(&self, item_type: &UIItemType) -> Option<String> {
+ let action = crate::termwindow::tooltip_action_for(item_type)?;
+ let mut chords = self
+ .input_map
+ .locate_app_wide_key_assignment(&action)
+ .into_iter()
+ .map(|(key, mods)| crate::inputmap::canonical_chord(&key, mods))
+ .collect::<Vec<_>>();
+ let native =
+ |mods: &Modifiers| mods.contains(Modifiers::SUPER) == cfg!(target_os = "macos");
+ chords.sort_by(|(a_key, a_mods), (b_key, b_mods)| {
+ native(b_mods)
+ .cmp(&native(a_mods))
+ .then(a_mods.bits().cmp(&b_mods.bits()))
+ .then(a_key.cmp(b_key))
+ });
+ let (key, mods) = chords.into_iter().next()?;
+ let rendering = self.config.ui_key_cap_rendering;
+ let label = crate::inputmap::chord_label(&key, mods, rendering);
+ // Set tight, as the Mac's menus write it: ⌘P, not ⌘ P.
+ Some(if rendering == UIKeyCapRendering::AppleSymbols {
+ label.replace(' ', "")
+ } else {
+ label
+ })
+ }
+
+ fn hover_style(&self) -> anyhow::Result<HoverStyle> {
+ let settings = crate::native_settings::load_shared();
+ let font_size = crate::native_settings::home_font_size(&settings);
+ let body = self
+ .fonts
+ .title_font_with_size_and_weight(font_size, 400)
+ .context("hover font")?;
+ let strong = self
+ .fonts
+ .title_font_with_size_and_weight(font_size, 600)
+ .context("hover heading font")?;
+ let metrics = RenderMetrics::with_font_metrics(&body.metrics());
+ let strong_metrics = RenderMetrics::with_font_metrics(&strong.metrics());
+ let mut palette = self.chrome().as_menu_card();
+ crate::native_settings::apply_ui_colors(&mut palette, self.config.ui_colors.as_ref());
+ Ok(HoverStyle {
+ line: metrics.cell_size.height as f32,
+ body,
+ strong,
+ metrics,
+ strong_metrics,
+ palette,
+ font_size,
+ })
+ }
+
+ fn paint_hover_surface(
+ &self,
+ layers: &mut TripleLayerQuadAllocator,
+ style: &HoverStyle,
+ rect: euclid::Rect<f32, window::PixelUnit>,
+ radius: f32,
+ ) -> anyhow::Result<()> {
+ let render_state = self.render_state.as_ref().context("hover render state")?;
+ let ctx = DrawContext::new(render_state, self.dimensions, &style.metrics);
+ let shadow = if style.palette.is_dark() { 0.58 } else { 0.43 };
+ ctx.draw_elevated_surface(
+ layers,
+ 0,
+ rect,
+ style.palette.control_bg,
+ style.palette.control_border,
+ LinearRgba::with_components(0.0, 0.0, 0.0, shadow),
+ radius,
+ )
+ .context("hover surface")
+ }
+
+ /// `text` broken into at most `max_lines` lines no wider than `width`,
+ /// as byte ranges into it: before a word that would not fit, after a `/`
+ /// so a path breaks between directories, or -- with neither near, or in
+ /// text without spaces -- right where it runs over. The last line keeps
+ /// the rest, for the painter to fade if it still runs over.
+ fn wrap_hover_text(
+ &self,
+ font: &Rc<LoadedFont>,
+ metrics: &RenderMetrics,
+ text: &str,
+ width: f32,
+ max_lines: usize,
+ ) -> anyhow::Result<Vec<Range<usize>>> {
+ let (shaped, _) = self.cached_ui_shape(font, metrics, text)?;
+ let glyphs: Vec<(usize, f32)> = shaped
+ .iter()
+ .map(|info| (info.cluster, info.glyph.x_advance.get() as f32))
+ .collect();
+ Ok(wrap_glyphs(text, &glyphs, width, max_lines))
+ }
+
+ fn paint_hover_tag(
+ &mut self,
+ item: &UIItem,
+ label: &str,
+ shortcut: Option<&str>,
+ style: &HoverStyle,
+ ) -> anyhow::Result<()> {
+ let window_w = self.dimensions.pixel_width as f32;
+ let window_h = self.dimensions.pixel_height as f32;
+ let max_width = self.ui_f32(TAG_MAX_WIDTH).min(window_w * 0.6).max(80.0);
+ let lines =
+ self.wrap_hover_text(&style.body, &style.metrics, label, max_width, TAG_LINES)?;
+ let mut text_width = 0.0f32;
+ for range in &lines {
+ text_width = text_width.max(self.cached_ui_text_advance(
+ &style.body,
+ &style.metrics,
+ &label[range.clone()],
+ )?);
+ }
+ let text_width = text_width.min(max_width).ceil();
+ // The shortcut sits after a one-line label, a step smaller and
+ // dimmer, on the label's baseline: the key symbols come from a
+ // fallback font and at full size outweigh the words.
+ let shortcut = match shortcut {
+ Some(keys) if lines.len() == 1 => {
+ let font = self
+ .fonts
+ .title_font_with_size_and_weight(style.font_size * SHORTCUT_SCALE, 400)
+ .context("hover shortcut font")?;
+ let metrics = RenderMetrics::with_font_metrics(&font.metrics());
+ let width = self.cached_ui_text_advance(&font, &metrics, keys)?.ceil();
+ Some((keys, font, metrics, width))
+ }
+ _ => None,
+ };
+ let key_gap = self.ui_f32(SHORTCUT_GAP);
+ let key_width = shortcut
+ .as_ref()
+ .map_or(0.0, |(_, _, _, width)| key_gap + width);
+ let (pad_x, pad_y, gap) = (
+ self.ui_f32(TAG_PAD_X),
+ self.ui_f32(TAG_PAD_Y),
+ self.ui_f32(GAP) / 2.0,
+ );
+ let spacing = self.ui_f32(LINE_SPACING);
+ let tip_w = text_width + key_width + pad_x * 2.0;
+ let tip_h = style.line * lines.len() as f32
+ + spacing * lines.len().saturating_sub(1) as f32
+ + pad_y * 2.0;
+
+ // Above the button. Beside it would sit on top of the neighbouring
+ // buttons in the same row -- these are laid out horizontally, so the
+ // only free direction is up. Below when there is no room above.
+ // Full-width list rows left-align their tag; icon buttons centre it.
+ let (bx, by, bw, bh) = (
+ item.x as f32,
+ item.y as f32,
+ item.width as f32,
+ item.height as f32,
+ );
+ let left_align = crate::termwindow::tooltip_left_aligns(&item.item_type);
+ let x = crate::termwindow::tooltip_anchor_x(bx, bw, tip_w, window_w, left_align);
+ let y = if by - gap - tip_h >= 0.0 {
+ by - gap - tip_h
+ } else {
+ (by + bh + gap).min((window_h - tip_h).max(0.0))
+ };
+
+ let gl_state = self.render_state.as_ref().context("hover render state")?;
+ let layer = gl_state
+ .layer_for_zindex(crate::termwindow::TOOLTIP_ZINDEX)
+ .context("hover tooltip layer")?;
+ let mut layers = layer.quad_allocator();
+ self.paint_hover_surface(
+ &mut layers,
+ style,
+ euclid::rect(x, y, tip_w, tip_h),
+ self.ui_f32(TAG_RADIUS),
+ )?;
+ let mut line_y = y + pad_y;
+ for range in &lines {
+ self.paint_agent_text(
+ &mut layers,
+ &style.body,
+ style.metrics,
+ &label[range.clone()],
+ (x + pad_x).round() as usize,
+ line_y.round() as usize,
+ text_width as usize,
+ style.palette.text,
+ )?;
+ line_y += style.line + spacing;
+ }
+ if let Some((keys, font, metrics, width)) = shortcut {
+ let baseline = |m: &RenderMetrics| m.cell_size.height as f32 + m.descender.get() as f32;
+ let top = y + pad_y + baseline(&style.metrics) - baseline(&metrics);
+ self.paint_agent_text(
+ &mut layers,
+ &font,
+ metrics,
+ keys,
+ (x + pad_x + text_width + key_gap).round() as usize,
+ top.round() as usize,
+ width as usize + 1,
+ style.palette.muted_text,
+ )?;
+ }
+ Ok(())
+ }
+
+ /// Where a card goes beside `item`: on the `prefer_right` side when it
+ /// fits there, the other side when not; top-aligned with the item and
+ /// kept inside the window.
+ fn hover_card_origin(
+ &self,
+ item: &UIItem,
+ card_w: f32,
+ card_h: f32,
+ prefer_right: bool,
+ ) -> (f32, f32) {
+ let window_w = self.dimensions.pixel_width as f32;
+ let window_h = self.dimensions.pixel_height as f32;
+ // Rows sit inside their sidebar's padding: a card a tag's distance
+ // from the row would overlap the sidebar's edge.
+ let gap = self.ui_f32(CARD_GAP);
+ let right = item.x as f32 + item.width as f32 + gap;
+ let left = item.x as f32 - gap - card_w;
+ let on_right = if prefer_right {
+ right + card_w <= window_w || left < 0.0
+ } else {
+ left < 0.0 && right + card_w <= window_w
+ };
+ // Where neither side has room, inside the window over the item.
+ let x = (if on_right { right } else { left }).clamp(0.0, (window_w - card_w).max(0.0));
+ let y = (item.y as f32).min(window_h - card_h).max(0.0);
+ (x, y)
+ }
+
+ fn paint_hover_state_icon(
+ &self,
+ layers: &mut TripleLayerQuadAllocator,
+ state: ShownState,
+ x: f32,
+ y: f32,
+ size: f32,
+ style: &HoverStyle,
+ ) -> anyhow::Result<()> {
+ let palette = style.palette;
+ let Some((icon, color, spinning)) = agent_state_icon(state, palette, palette.muted_text)
+ else {
+ return Ok(());
+ };
+ let (x, y, size) = (
+ x.round() as usize,
+ y.round() as usize,
+ size.round() as usize,
+ );
+ if spinning {
+ self.paint_spinning_ui_icon(layers, 2, icon, x, y, size, color)
+ } else {
+ self.paint_sidebar_icon(layers, icon, x, y, size, color)
+ }
+ }
+
+ /// The sizes both cards are laid out with.
+ fn card_frame(&self, style: &HoverStyle) -> CardFrame {
+ let window_w = self.dimensions.pixel_width as f32;
+ CardFrame {
+ width: self.ui_f32(CARD_WIDTH).min(window_w * 0.45),
+ pad_x: self.ui_f32(CARD_PAD_X),
+ pad_y: self.ui_f32(CARD_PAD_Y),
+ gap: self.ui_f32(GAP),
+ spacing: self.ui_f32(LINE_SPACING),
+ line: style.line,
+ }
+ }
+
+ fn paint_hover_separator(
+ &self,
+ layers: &mut TripleLayerQuadAllocator,
+ x: f32,
+ y: f32,
+ width: f32,
+ style: &HoverStyle,
+ ) -> anyhow::Result<()> {
+ self.fill_rounded_rectangle(
+ layers,
+ 1,
+ euclid::rect(x, y.round(), width, 1.0),
+ style.palette.separator,
+ 0.0,
+ )
+ .context("hover separator")
+ }
+
+ /// A thread row's card: the thread's name and how many agents it holds,
+ /// then each agent in two lines -- its mark, title and state icon, then
+ /// its state in words, how far it has got, what it waits for and what it
+ /// says -- parted by hairlines. Beside the row rather than above it: the
+ /// card is taller than a tag, and the rows above are the ones being read.
+ fn paint_thread_hover_card(
+ &mut self,
+ item: &UIItem,
+ agents: &[AgentPaneStatus],
+ style: &HoverStyle,
+ ) -> anyhow::Result<()> {
+ let show = crate::native_settings::agent_status_display();
+ let CardFrame {
+ width: card_w,
+ pad_x,
+ pad_y,
+ gap,
+ spacing,
+ line,
+ } = self.card_frame(style);
+ let mark = line;
+ let text_x = pad_x + mark + gap / 2.0;
+ let text_w = card_w - text_x - pad_x - mark - gap / 2.0;
+ let entry_h = line * 2.0 + spacing;
+ let header_h = line;
+ // As many agents as the window has room for, in order, and a last
+ // line saying how many more there are.
+ let head_h = pad_y * 2.0 + header_h + gap + 1.0 + gap;
+ let rows_h = |rows: usize| entry_h * rows as f32 + gap * rows.saturating_sub(1) as f32;
+ let more_h = gap + line;
+ let room = self.dimensions.pixel_height as f32 - gap * 2.0;
+ let card_h_for =
+ |rows: usize| head_h + rows_h(rows) + if rows < agents.len() { more_h } else { 0.0 };
+ let rows = (1..=agents.len())
+ .rev()
+ .find(|&rows| card_h_for(rows) <= room)
+ .unwrap_or(1)
+ .min(agents.len());
+ let card_h = card_h_for(rows);
+ let (x, y) = self.hover_card_origin(item, card_w, card_h, true);
+
+ let place = agents
+ .iter()
+ .map(|agent| agent.place.as_str())
+ .find(|place| !place.is_empty())
+ .unwrap_or_default()
+ .to_string();
+ let mut args = fluent_bundle::FluentArgs::new();
+ args.set("count", agents.len());
+ let count = crate::i18n::tr_args("hover-card-agents", &args);
+ let count_w = self
+ .cached_ui_text_advance(&style.body, &style.metrics, &count)?
+ .ceil();
+
+ let gl_state = self.render_state.as_ref().context("hover render state")?;
+ let layer = gl_state
+ .layer_for_zindex(crate::termwindow::TOOLTIP_ZINDEX)
+ .context("thread card layer")?;
+ let mut layers = layer.quad_allocator();
+ self.paint_hover_surface(
+ &mut layers,
+ style,
+ euclid::rect(x, y, card_w, card_h),
+ self.ui_f32(CARD_RADIUS),
+ )?;
+
+ // The thread, and how many agents it holds.
+ let mut cy = y + pad_y;
+ self.paint_agent_text(
+ &mut layers,
+ &style.strong,
+ style.strong_metrics,
+ &place,
+ (x + pad_x).round() as usize,
+ cy.round() as usize,
+ (card_w - pad_x * 2.0 - count_w - gap).max(0.0) as usize,
+ style.palette.text,
+ )?;
+ self.paint_agent_text(
+ &mut layers,
+ &style.body,
+ style.metrics,
+ &count,
+ (x + card_w - pad_x - count_w).round() as usize,
+ cy.round() as usize,
+ count_w as usize,
+ style.palette.muted_text,
+ )?;
+ cy += header_h + gap;
+ self.paint_hover_separator(&mut layers, x, cy, card_w, style)?;
+ cy += 1.0 + gap;
+
+ let right = x + text_x + text_w;
+ for agent in &agents[..rows] {
+ let state = agent.shown_state();
+ let brand = brand_of(agent);
+ self.paint_agent_mark(
+ &mut layers,
+ brand,
+ (x + pad_x).round() as usize,
+ cy.round() as usize,
+ mark.round() as usize,
+ style.palette.secondary_text,
+ )?;
+ self.paint_hover_state_icon(
+ &mut layers,
+ state,
+ x + card_w - pad_x - mark,
+ cy,
+ mark,
+ style,
+ )?;
+ self.paint_agent_text(
+ &mut layers,
+ &style.strong,
+ style.strong_metrics,
+ &agent_row_title(agent, brand),
+ (x + text_x).round() as usize,
+ cy.round() as usize,
+ text_w.max(0.0) as usize,
+ style.palette.text,
+ )?;
+
+ // The state in words, so it never rests on the icon's colour
+ // alone, and how far it has got; then why it waits and what it
+ // says.
+ let said_y = (cy + line + spacing).round() as usize;
+ let (kind, msg) = agent_status::report_said(agent, show);
+ let mut status = crate::i18n::tr(agent_state_key(state));
+ if let Some(progress) = agent_status::report_progress(agent, show) {
+ status = format!("{status} \u{b7} {progress}%");
+ }
+ if kind.is_some() || msg.is_some() {
+ status.push_str(" \u{b7} ");
+ }
+ let mut said_x = x + text_x;
+ let status_w = self
+ .cached_ui_text_advance(&style.body, &style.metrics, &status)?
+ .ceil();
+ self.paint_agent_text(
+ &mut layers,
+ &style.body,
+ style.metrics,
+ &status,
+ said_x.round() as usize,
+ said_y,
+ status_w.min(right - said_x).max(0.0) as usize,
+ style.palette.muted_text,
+ )?;
+ said_x += status_w;
+ if let Some(kind) = kind {
+ let label = crate::i18n::tr(agent_status::blocked_kind_key(kind));
+ said_x = self.paint_agent_kind_pill(
+ &mut layers,
+ &style.body,
+ style.metrics,
+ &label,
+ said_x.round() as usize,
+ said_y,
+ right.max(0.0) as usize,
+ )? as f32;
+ }
+ if let Some(msg) = msg {
+ let color = said_color(state, style);
+ self.paint_agent_text(
+ &mut layers,
+ &style.body,
+ style.metrics,
+ msg,
+ said_x.round() as usize,
+ said_y,
+ (right - said_x).max(0.0) as usize,
+ color,
+ )?;
+ }
+ cy += entry_h + gap;
+ }
+ let more = agents.len() - rows;
+ if more > 0 {
+ let mut args = fluent_bundle::FluentArgs::new();
+ args.set("count", more);
+ self.paint_agent_text(
+ &mut layers,
+ &style.body,
+ style.metrics,
+ &crate::i18n::tr_args("hover-card-more-agents", &args),
+ (x + text_x).round() as usize,
+ cy.round() as usize,
+ text_w.max(0.0) as usize,
+ style.palette.muted_text,
+ )?;
+ }
+ Ok(())
+ }
+
+ /// An Agents panel row's card: everything the row has no room for. The
+ /// title and the description in full (wrapped), the agent and its state,
+ /// progress, then where it runs, on which machine, for how long it has
+ /// been in this state and its sub-tasks. Left of the panel, which runs
+ /// along the window's right edge.
+ fn paint_agent_hover_card(
+ &mut self,
+ item: &UIItem,
+ agent: &AgentPaneStatus,
+ style: &HoverStyle,
+ ) -> anyhow::Result<()> {
+ let show = crate::native_settings::agent_status_display();
+ let CardFrame {
+ width: card_w,
+ pad_x,
+ pad_y,
+ gap,
+ spacing,
+ line,
+ } = self.card_frame(style);
+ let mark = line;
+ let inner_w = card_w - pad_x * 2.0;
+ let shown = agent.shown_state();
+
+ let title = agent_title(agent);
+ let title_w = inner_w - mark - gap / 2.0;
+ let wrap_title = |this: &Self, lines: usize| {
+ this.wrap_hover_text(&style.strong, &style.strong_metrics, &title, title_w, lines)
+ };
+ let mut title_lines = wrap_title(self, CARD_TITLE_LINES)?;
+ let subtitle = format!(
+ "{} \u{b7} {}",
+ agent_status::display_name(&agent.agent_id),
+ crate::i18n::tr(agent_state_key(shown))
+ );
+ let (kind, msg) = agent_status::report_said(agent, show);
+ let wrap_msg = |this: &Self, lines: usize| match msg {
+ Some(msg) => this.wrap_hover_text(&style.body, &style.metrics, msg, inner_w, lines),
+ None => Ok(Vec::new()),
+ };
+ let mut msg_lines = wrap_msg(self, CARD_MESSAGE_LINES)?;
+ let progress = agent_status::report_progress(agent, show);
+ let facts = self.agent_card_facts(agent, show);
+ let mut label_w = 0.0f32;
+ for (label, _) in &facts {
+ label_w =
+ label_w.max(self.cached_ui_text_advance(&style.body, &style.metrics, label)?);
+ }
+ let label_w = label_w.ceil();
+
+ let lines_h = |count: usize| line * count as f32 + spacing * count.saturating_sub(1) as f32;
+ let bar_h = self.ui_px(AGENT_PROGRESS_HEIGHT) as f32;
+ let said = kind.is_some() || !msg_lines.is_empty() || progress.is_some();
+ // Everything but the title's and the description's lines, which are
+ // what gives way when the window is too short for the card: the
+ // description down to one line, then the title, each fading where
+ // it is cut.
+ let fixed = pad_y * 2.0
+ + spacing
+ + line
+ + if said {
+ gap + 1.0
+ + gap
+ + if kind.is_some() { line + spacing } else { 0.0 }
+ + progress.map_or(0.0, |_| gap / 2.0 + bar_h)
+ } else {
+ 0.0
+ }
+ + gap
+ + 1.0
+ + gap
+ + lines_h(facts.len());
+ let card_h_for = |title: usize, msg: usize| fixed + lines_h(title.max(1)) + lines_h(msg);
+ let room = self.dimensions.pixel_height as f32 - gap * 2.0;
+ let over = |height: f32| ((height - room) / (line + spacing)).ceil().max(0.0) as usize;
+ let excess = over(card_h_for(title_lines.len(), msg_lines.len()));
+ if excess > 0 && msg_lines.len() > 1 {
+ msg_lines = wrap_msg(self, msg_lines.len().saturating_sub(excess).max(1))?;
+ }
+ if over(card_h_for(title_lines.len(), msg_lines.len())) > 0 && title_lines.len() > 1 {
+ title_lines = wrap_title(self, 1)?;
+ }
+ let card_h = card_h_for(title_lines.len(), msg_lines.len());
+ let (x, y) = self.hover_card_origin(item, card_w, card_h, false);
+
+ let gl_state = self.render_state.as_ref().context("hover render state")?;
+ let layer = gl_state
+ .layer_for_zindex(crate::termwindow::TOOLTIP_ZINDEX)
+ .context("agent card layer")?;
+ let mut layers = layer.quad_allocator();
+ self.paint_hover_surface(
+ &mut layers,
+ style,
+ euclid::rect(x, y, card_w, card_h),
+ self.ui_f32(CARD_RADIUS),
+ )?;
+
+ // Mark and title, then which agent and in what state.
+ let left = x + pad_x;
+ let mut cy = y + pad_y;
+ self.paint_agent_mark(
+ &mut layers,
+ brand_of(agent),
+ left.round() as usize,
+ cy.round() as usize,
+ mark.round() as usize,
+ style.palette.secondary_text,
+ )?;
+ for range in &title_lines {
+ self.paint_agent_text(
+ &mut layers,
+ &style.strong,
+ style.strong_metrics,
+ &title[range.clone()],
+ (left + mark + gap / 2.0).round() as usize,
+ cy.round() as usize,
+ title_w.max(0.0) as usize,
+ style.palette.text,
+ )?;
+ cy += line + spacing;
+ }
+ if title_lines.is_empty() {
+ cy += line + spacing;
+ }
+ self.paint_agent_text(
+ &mut layers,
+ &style.body,
+ style.metrics,
+ &subtitle,
+ (left + mark + gap / 2.0).round() as usize,
+ cy.round() as usize,
+ title_w.max(0.0) as usize,
+ style.palette.muted_text,
+ )?;
+ cy += line;
+
+ // What it is doing or waits for, and how far it has got.
+ if said {
+ cy += gap;
+ self.paint_hover_separator(&mut layers, x, cy, card_w, style)?;
+ cy += 1.0 + gap;
+ if let Some(kind) = kind {
+ let label = crate::i18n::tr(agent_status::blocked_kind_key(kind));
+ self.paint_agent_kind_pill(
+ &mut layers,
+ &style.body,
+ style.metrics,
+ &label,
+ left.round() as usize,
+ cy.round() as usize,
+ (left + inner_w).max(0.0) as usize,
+ )?;
+ cy += line + spacing;
+ }
+ if let Some(msg) = msg {
+ let color = said_color(shown, style);
+ for range in &msg_lines {
+ self.paint_agent_text(
+ &mut layers,
+ &style.body,
+ style.metrics,
+ &msg[range.clone()],
+ left.round() as usize,
+ cy.round() as usize,
+ inner_w.max(0.0) as usize,
+ color,
+ )?;
+ cy += line + spacing;
+ }
+ cy -= spacing;
+ }
+ if let Some(progress) = progress {
+ cy += gap / 2.0;
+ self.paint_agent_progress(
+ &mut layers,
+ euclid::rect(left, cy, inner_w, bar_h),
+ progress,
+ style.palette.separator,
+ style.palette.accent,
+ )?;
+ cy += bar_h;
+ }
+ }
+
+ // Where, on which machine, for how long, and its sub-tasks.
+ cy += gap;
+ self.paint_hover_separator(&mut layers, x, cy, card_w, style)?;
+ cy += 1.0 + gap;
+ let value_x = left + label_w + gap;
+ for (label, value) in &facts {
+ self.paint_agent_text(
+ &mut layers,
+ &style.body,
+ style.metrics,
+ label,
+ left.round() as usize,
+ cy.round() as usize,
+ label_w as usize,
+ style.palette.muted_text,
+ )?;
+ self.paint_agent_text(
+ &mut layers,
+ &style.body,
+ style.metrics,
+ value,
+ value_x.round() as usize,
+ cy.round() as usize,
+ (left + inner_w - value_x).max(0.0) as usize,
+ style.palette.secondary_text,
+ )?;
+ cy += line + spacing;
+ }
+ Ok(())
+ }
+
+ /// The labelled facts an agent card ends with. The machine's name reads
+ /// the host list, so it is looked up the first time the card paints and
+ /// kept with the hover; with no thread behind the agent's workspace there
+ /// is no saying which machine, and the fact is left out. How long the
+ /// agent has been in its state is painted again when that label next
+ /// changes.
+ fn agent_card_facts(
+ &mut self,
+ agent: &AgentPaneStatus,
+ show: crate::native_settings::NativeAgentStatusDisplay,
+ ) -> Vec<(String, String)> {
+ let mut facts = Vec::with_capacity(4);
+ if !agent.place.is_empty() {
+ facts.push((crate::i18n::tr("hover-card-thread"), agent.place.clone()));
+ }
+ let kept = self
+ .hover_tooltip
+ .as_ref()
+ .and_then(|hover| hover.machine.clone());
+ let machine = match kept {
+ Some(machine) => machine,
+ None => {
+ let machine = crate::workspace_threads::thread_machine_label(&agent.workspace)
+ .map(|label| label.unwrap_or_else(|| crate::i18n::tr("menu-machine-local")));
+ if let Some(hover) = self.hover_tooltip.as_mut() {
+ hover.machine = Some(machine.clone());
+ }
+ machine
+ }
+ };
+ if let Some(machine) = machine {
+ facts.push((crate::i18n::tr("hover-card-machine"), machine));
+ }
+ let now = SystemTime::now()
+ .duration_since(UNIX_EPOCH)
+ .map(|d| d.as_secs())
+ .unwrap_or(0);
+ if agent.since_unix > 0 {
+ let elapsed = now.saturating_sub(agent.since_unix);
+ facts.push((
+ crate::i18n::tr("hover-card-duration"),
+ elapsed_label(elapsed),
+ ));
+ self.update_next_frame_time(Some(
+ Instant::now() + Duration::from_secs(label_changes_in(elapsed)),
+ ));
+ }
+ if let Some(report) = agent.report.as_ref().filter(|_| show.subtasks) {
+ if !report.children.is_empty() {
+ let working = working_subtasks(report);
+ let mut value = report.children.len().to_string();
+ if working > 0 {
+ let mut args = fluent_bundle::FluentArgs::new();
+ args.set("count", working);
+ value = format!(
+ "{value} \u{b7} {}",
+ crate::i18n::tr_args("right-agents-count-working", &args)
+ );
+ }
+ facts.push((crate::i18n::tr("hover-card-subtasks"), value));
+ }
+ }
+ facts
+ }
+}
+
+/// How long ago, in the largest whole unit that fits.
+fn elapsed_label(seconds: u64) -> String {
+ let (key, count) = match seconds {
+ 0..=59 => return crate::i18n::tr("hover-card-under-a-minute"),
+ 60..=3599 => ("hover-card-minutes", seconds / 60),
+ 3600..=86_399 => ("hover-card-hours", seconds / 3600),
+ _ => ("hover-card-days", seconds / 86_400),
+ };
+ let mut args = fluent_bundle::FluentArgs::new();
+ args.set("count", count);
+ crate::i18n::tr_args(key, &args)
+}
+
+/// Seconds until [`elapsed_label`] reads differently.
+fn label_changes_in(seconds: u64) -> u64 {
+ let unit = match seconds {
+ 0..=3599 => 60,
+ 3600..=86_399 => 3600,
+ _ => 86_400,
+ };
+ unit - seconds % unit
+}
+
+/// The sizes a card is laid out with: its width, its padding, the gap
+/// between its parts, the spacing between wrapped lines and a line's height.
+struct CardFrame {
+ width: f32,
+ pad_x: f32,
+ pad_y: f32,
+ gap: f32,
+ spacing: f32,
+ line: f32,
+}
+
+/// What an agent says is set in the card's grey, or red when it failed.
+fn said_color(state: ShownState, style: &HoverStyle) -> LinearRgba {
+ if state == ShownState::Error {
+ style.palette.danger
+ } else {
+ style.palette.secondary_text
+ }
+}
+
+/// Punctuation that closes, which no line may start with.
+fn closes(c: char) -> bool {
+ ",。、:;!?)」』】》〉〕}〗〙・…ー々ゝゞヽヾ”’,.:;!?)]}".contains(c)
+}
+
+/// Punctuation that opens, which no line may end with.
+fn opens(c: char) -> bool {
+ "(「『【《〈〔{〖〘“‘([{".contains(c)
+}
+
+/// The line breaks for glyphs -- (cluster byte offset, advance) in order --
+/// of `text`, as `TermWindow::wrap_hover_text` describes them.
+fn wrap_glyphs(
+ text: &str,
+ glyphs: &[(usize, f32)],
+ width: f32,
+ max_lines: usize,
+) -> Vec<Range<usize>> {
+ let char_at = |cluster: usize| text.get(cluster..).and_then(|rest| rest.chars().next());
+ let mut lines = Vec::new();
+ let mut start = 0usize;
+ while lines.len() + 1 < max_lines && start < glyphs.len() {
+ let origin = glyphs[start].0;
+ let mut x = 0.0f32;
+ let mut over = None;
+ for (i, &(_, advance)) in glyphs.iter().enumerate().skip(start) {
+ x += advance;
+ if x > width && i > start {
+ over = Some(i);
+ break;
+ }
+ }
+ let Some(over) = over else {
+ break;
+ };
+ // The latest place to break before `over`: before a space, after a
+ // slash, or between two characters of a script set without spaces --
+ // but never before closing punctuation or after opening, so no line
+ // starts with "," or ends with "(".
+ let mut cut = None;
+ for i in (start + 1..=over).rev() {
+ let here = char_at(glyphs[i].0);
+ let before = char_at(glyphs[i - 1].0);
+ let wide = |c: Option<char>| c.is_some_and(|c| c as u32 >= 0x2E80);
+ let breaks = here.is_some_and(char::is_whitespace)
+ || before == Some('/')
+ || ((wide(here) || wide(before))
+ && !here.is_some_and(closes)
+ && !before.is_some_and(opens));
+ if breaks {
+ cut = Some(i);
+ break;
+ }
+ }
+ let cut = cut.unwrap_or(over);
+ let end = glyphs[cut].0;
+ let line = text[origin..end].trim_end();
+ lines.push(origin..origin + line.len());
+ // The next line starts past the spaces at the break.
+ start = cut;
+ while start < glyphs.len() && char_at(glyphs[start].0).is_some_and(char::is_whitespace) {
+ start += 1;
+ }
+ }
+ if start < glyphs.len() {
+ let origin = glyphs[start].0;
+ let rest = text[origin..].trim_end();
+ lines.push(origin..origin + rest.len());
+ }
+ lines
+}
+
+/// The agent an Agents panel row reveals: the row's own pane.
+fn agent_row_pane(item_type: &UIItemType) -> Option<PaneId> {
+ match item_type {
+ UIItemType::RightSidebarAgent(
+ AgentPanelAction::Reveal(pane_id) | AgentPanelAction::RevealElsewhere(pane_id),
+ ) => Some(*pane_id),
+ _ => None,
+ }
+}
+
+/// The agent whose card an item shows: an Agents panel row's, over the row
+/// and over its sub-task line, a target of its own on top of the row.
+pub(crate) fn agent_card_pane(item_type: &UIItemType) -> Option<PaneId> {
+ match item_type {
+ UIItemType::RightSidebarAgent(AgentPanelAction::ToggleSubtasks(pane_id)) => Some(*pane_id),
+ _ => agent_row_pane(item_type),
+ }
+}
+
+/// Whether the pointer moving from `a` to `b` stays on one surface: the same
+/// item, or two parts of the same agent's row.
+pub(crate) fn same_hover_target(a: &UIItemType, b: &UIItemType) -> bool {
+ a == b || agent_card_pane(a).is_some_and(|pane_id| agent_card_pane(b) == Some(pane_id))
+}
+
+#[cfg(test)]
+mod tests {
+ use super::{label_changes_in, wrap_glyphs};
+
+ /// One unit of advance per character, the cluster its byte offset.
+ fn lines(text: &str, width: f32, max: usize) -> Vec<&str> {
+ let glyphs: Vec<(usize, f32)> = text.char_indices().map(|(at, _)| (at, 1.0)).collect();
+ wrap_glyphs(text, &glyphs, width, max)
+ .into_iter()
+ .map(|range| &text[range])
+ .collect()
+ }
+
+ #[test]
+ fn short_text_is_one_line() {
+ assert_eq!(lines("Find Thread", 20.0, 3), ["Find Thread"]);
+ }
+
+ #[test]
+ fn words_wrap_before_the_one_that_does_not_fit() {
+ assert_eq!(
+ lines("alpha beta gamma delta", 11.0, 3),
+ ["alpha beta", "gamma delta"]
+ );
+ }
+
+ #[test]
+ fn paths_wrap_after_a_slash() {
+ assert_eq!(
+ lines("/home/user/project/src/main.rs", 12.0, 3),
+ ["/home/user/", "project/src/", "main.rs"]
+ );
+ }
+
+ #[test]
+ fn the_time_in_a_state_is_redrawn_when_its_label_changes() {
+ assert_eq!(label_changes_in(0), 60);
+ assert_eq!(label_changes_in(59), 1);
+ assert_eq!(label_changes_in(61), 59);
+ assert_eq!(label_changes_in(3599), 1);
+ assert_eq!(label_changes_in(3600), 3600);
+ assert_eq!(label_changes_in(86_399), 1);
+ assert_eq!(label_changes_in(86_400), 86_400);
+ }
+
+ #[test]
+ fn the_last_line_keeps_the_rest() {
+ assert_eq!(
+ lines("one two three four five six", 8.0, 2),
+ ["one two", "three four five six"]
+ );
+ }
+
+ #[test]
+ fn no_line_starts_with_closing_punctuation() {
+ assert_eq!(
+ lines("终端软件,推荐比较", 4.0, 3),
+ ["终端软", "件,推荐", "比较"]
+ );
+ assert_eq!(lines("终端软件(推荐)", 5.0, 3), ["终端软件", "(推荐)"]);
+ assert_eq!(lines("运行“测试”完成", 3.0, 3), ["运行", "“测", "试”完成"]);
+ }
+
+ #[test]
+ fn text_without_spaces_breaks_anywhere() {
+ assert_eq!(
+ lines("终端软件推荐与比较", 4.0, 3),
+ ["终端软件", "推荐与比", "较"]
+ );
+ assert_eq!(lines("abcdefghij", 4.0, 2), ["abcd", "efghij"]);
+ }
+}
diff --git a/wezterm-gui/src/termwindow/render/mod.rs b/wezterm-gui/src/termwindow/render/mod.rs
index 283964cf..7267d86e 100644
--- a/wezterm-gui/src/termwindow/render/mod.rs
+++ b/wezterm-gui/src/termwindow/render/mod.rs
@@ -45,6 +45,7 @@ pub mod borders;
pub mod corners;
pub mod draw;
pub mod fancy_tab_bar;
+pub mod hover;
pub mod paint;
pub mod pane;
pub mod screen_line;
diff --git a/wezterm-gui/src/termwindow/render/paint.rs b/wezterm-gui/src/termwindow/render/paint.rs
index bf87118a..e9e8834a 100644
--- a/wezterm-gui/src/termwindow/render/paint.rs
+++ b/wezterm-gui/src/termwindow/render/paint.rs
@@ -3364,277 +3364,6 @@ impl crate::TermWindow {
/// Floating label that follows the cursor during a drag. Painted after
/// everything else so it stays on top; registers no UIItem.
- /// Name tag for an icon-only button the pointer has been resting on.
- ///
- /// Anchored beside the button rather than under the pointer: the pointer
- /// is already sitting on the icon, so a tag placed under it would cover
- /// the very thing it names.
- fn paint_hover_tooltip(&mut self) -> anyhow::Result<()> {
- let Some(hover) = self.hover_tooltip.clone() else {
- return Ok(());
- };
- let remaining = crate::termwindow::TOOLTIP_DELAY.saturating_sub(hover.since.elapsed());
- if !remaining.is_zero() {
- // Ask for the frame that will find the delay elapsed. This has to
- // happen here and not where the pointer arrived: paint_impl clears
- // has_animation on entry, so a deadline registered from the mouse
- // handler is wiped before anything can read it, and the tag would
- // then only appear when some unrelated event forced a repaint.
- self.update_next_frame_time(Some(Instant::now() + remaining));
- return Ok(());
- }
- // Re-check the dynamic conditions at paint time: a rename started
- // from a key assignment (no mouse event) or a row whose label no
- // longer overflows must suppress an already-armed tag.
- if !self.hover_tooltip_allowed(&hover.item.item_type) {
- return Ok(());
- }
- let agents = crate::termwindow::thread_card_agents(&hover.item.item_type);
- if !agents.is_empty() {
- return self.paint_thread_agent_card(&hover.item, &agents);
- }
- let Some(label) = crate::termwindow::tooltip_label_for(&hover.item.item_type) else {
- return Ok(());
- };
-
- let settings = crate::native_settings::load_shared();
- let font_size = crate::native_settings::home_font_size(&settings);
- let ui_font = self
- .fonts
- .title_font_with_size(font_size)
- .context("hover tooltip font")?;
- let metrics = crate::utilsprites::RenderMetrics::with_font_metrics(&ui_font.metrics());
- let line_height = metrics.cell_size.height as f32;
-
- // From the shared chrome palette, not a hand-picked grey: the tag sits
- // directly against the sidebar it overhangs, so anything lighter than
- // the sidebar's own controls reads as a foreign surface.
- let chrome = self.chrome();
-
- let gl_state = self.render_state.as_ref().unwrap();
- let layer = gl_state
- .layer_for_zindex(crate::termwindow::TOOLTIP_ZINDEX)
- .context("hover tooltip layer")?;
- let mut layers = layer.quad_allocator();
-
- let ctx = DrawContext::new(gl_state, self.dimensions, &metrics);
- let max_width = (self.dimensions.pixel_width as f32 * 0.4).max(80.0);
- let display_text = ctx.text_with_ellipsis(&ui_font, &label, max_width);
- let text_width = ctx
- .measure_text_width(&ui_font, &display_text)
- .min(max_width);
-
- let pad_x = self.ui_f32(8.0);
- let pad_y = self.ui_f32(4.0);
- let gap = self.ui_f32(8.0);
- let tip_w = text_width + pad_x * 2.0;
- let tip_h = line_height + pad_y * 2.0;
-
- let (bx, by, bw, bh) = (
- hover.item.x as f32,
- hover.item.y as f32,
- hover.item.width as f32,
- hover.item.height as f32,
- );
- let window_w = self.dimensions.pixel_width as f32;
- let window_h = self.dimensions.pixel_height as f32;
-
- // Above the button. Beside it would sit on top of the neighbouring
- // buttons in the same row — these are laid out horizontally, so the
- // only free direction is up. Flip below when there is no room above.
- // Full-width list rows left-align their tag; icon buttons centre it.
- let left_align = crate::termwindow::tooltip_left_aligns(&hover.item.item_type);
- let x = crate::termwindow::tooltip_anchor_x(bx, bw, tip_w, window_w, left_align);
- let y = if by - gap - tip_h >= 0.0 {
- by - gap - tip_h
- } else {
- (by + bh + gap).min((window_h - tip_h).max(0.0))
- };
-
- self.fill_rounded_rectangle_with_border(
- &mut layers,
- 0,
- euclid::rect(x, y, tip_w, tip_h),
- chrome.control_bg,
- chrome.control_border,
- self.ui_f32(6.0),
- 1.0,
- )
- .context("hover tooltip background")?;
- ctx.draw_text_on_layer(
- &mut layers,
- 2,
- &ui_font,
- x + pad_x,
- y + pad_y,
- &display_text,
- chrome.text,
- max_width,
- )
- .context("hover tooltip label")?;
-
- Ok(())
- }
-
- /// A thread row's hover card: each agent in the thread, its state, and
- /// -- where its program said -- why it waits, how far it got and what it
- /// is doing. Beside the row rather than above it: the card is taller
- /// than a tag, and the rows above are the ones being read.
- fn paint_thread_agent_card(
- &mut self,
- item: &crate::termwindow::UIItem,
- agents: &[crate::agent_status::AgentPaneStatus],
- ) -> anyhow::Result<()> {
- use crate::agent_status::{self, ShownState};
- use crate::termwindow::ui::agent_panel::{agent_state_icon, agent_state_key};
-
- let settings = crate::native_settings::load_shared();
- let font_size = crate::native_settings::home_font_size(&settings);
- let ui_font = self
- .fonts
- .title_font_with_size(font_size)
- .context("thread card font")?;
- let metrics = crate::utilsprites::RenderMetrics::with_font_metrics(&ui_font.metrics());
- let line = metrics.cell_size.height as f32;
- let chrome = self.chrome();
- let show = settings.chrome.agent_status_display;
-
- // Per agent: its state, a heading, and what it said, if anything.
- let entries: Vec<(ShownState, String, Option<(String, LinearRgba)>)> = agents
- .iter()
- .map(|agent| {
- let shown = agent.shown_state();
- let mut heading = format!(
- "{} · {}",
- agent_status::display_name(&agent.agent_id),
- crate::i18n::tr(agent_state_key(shown))
- );
- let report = agent.report.as_ref();
- if let Some(kind) = report.and_then(|report| report.kind).filter(|_| show.reason) {
- heading.push_str(" · ");
- heading.push_str(&crate::i18n::tr(agent_status::blocked_kind_key(kind)));
- }
- if let Some(progress) = report
- .and_then(|report| report.progress)
- .filter(|_| show.progress)
- {
- heading.push_str(&format!(" · {progress}%"));
- }
- let said = report
- .and_then(|report| report.msg.clone())
- .filter(|_| show.description)
- .map(|msg| {
- let color = if shown == ShownState::Error {
- chrome.danger
- } else {
- chrome.secondary_text
- };
- (msg, color)
- });
- (shown, heading, said)
- })
- .collect();
-
- let gl_state = self.render_state.as_ref().unwrap();
- let layer = gl_state
- .layer_for_zindex(crate::termwindow::TOOLTIP_ZINDEX)
- .context("thread card layer")?;
- let mut layers = layer.quad_allocator();
- let ctx = DrawContext::new(gl_state, self.dimensions, &metrics);
-
- let pad = self.ui_f32(12.0);
- let gap = self.ui_f32(8.0);
- let icon = (line * 0.9).round().max(1.0);
- let max_text = (self.dimensions.pixel_width as f32 * 0.32).max(160.0);
- let text_width = entries
- .iter()
- .flat_map(|(_, heading, said)| {
- std::iter::once(heading.as_str()).chain(said.iter().map(|(text, _)| text.as_str()))
- })
- .map(|text| ctx.measure_text_width(&ui_font, text))
- .fold(0.0f32, f32::max)
- .min(max_text);
- let entry_height = |said: bool| line + if said { line + self.ui_f32(2.0) } else { 0.0 };
- let card_w = pad * 2.0 + icon + gap + text_width;
- let card_h = pad * 2.0
- + entries
- .iter()
- .map(|(_, _, said)| entry_height(said.is_some()))
- .sum::<f32>()
- + gap * entries.len().saturating_sub(1) as f32;
-
- let window_w = self.dimensions.pixel_width as f32;
- let window_h = self.dimensions.pixel_height as f32;
- let right_of_row = item.x as f32 + item.width as f32 + gap;
- let x = if right_of_row + card_w <= window_w {
- right_of_row
- } else {
- (item.x as f32 - gap - card_w).max(0.0)
- };
- let y = (item.y as f32).min(window_h - card_h).max(0.0);
-
- self.fill_rounded_rectangle_with_border(
- &mut layers,
- 0,
- euclid::rect(x, y, card_w, card_h),
- chrome.control_bg,
- chrome.control_border,
- self.ui_f32(10.0),
- 1.0,
- )
- .context("thread card background")?;
-
- let text_x = x + pad + icon + gap;
- let mut entry_y = y + pad;
- for (shown, heading, said) in &entries {
- if let Some((glyph, color, spinning)) =
- agent_state_icon(*shown, chrome, chrome.muted_text)
- {
- let icon_x = (x + pad).round() as usize;
- let icon_y = (entry_y + (line - icon) / 2.0).round() as usize;
- if spinning {
- self.paint_spinning_ui_icon(
- &mut layers,
- 2,
- glyph,
- icon_x,
- icon_y,
- icon as usize,
- color,
- )?;
- } else {
- self.paint_sidebar_icon(&mut layers, glyph, icon_x, icon_y, icon as usize, color)?;
- }
- }
- ctx.draw_text_on_layer(
- &mut layers,
- 2,
- &ui_font,
- text_x,
- entry_y,
- heading,
- chrome.text,
- text_width,
- )
- .context("thread card heading")?;
- if let Some((text, color)) = said {
- ctx.draw_text_on_layer(
- &mut layers,
- 2,
- &ui_font,
- text_x,
- entry_y + line + self.ui_f32(2.0),
- text,
- *color,
- text_width,
- )
- .context("thread card description")?;
- }
- entry_y += entry_height(said.is_some()) + gap;
- }
- Ok(())
- }
-
fn paint_drag_ghost_pill(
&mut self,
label: &str,
diff --git a/wezterm-gui/src/termwindow/ui/agent_panel.rs b/wezterm-gui/src/termwindow/ui/agent_panel.rs
index 6d9955b7..cde42d2b 100644
--- a/wezterm-gui/src/termwindow/ui/agent_panel.rs
+++ b/wezterm-gui/src/termwindow/ui/agent_panel.rs
@@ -4,7 +4,7 @@
//! snapshots — the paint path never triggers detection or filesystem
//! probes.
-use crate::agent_status::{self, AgentIcon, AgentPanelAction, ProgramReportState};
+use crate::agent_status::{self, AgentIcon, AgentPanelAction, ProgramReport, ProgramReportState};
use crate::quad::TripleLayerQuadAllocator;
use crate::termwindow::ui::icons::SvgIcon;
use crate::termwindow::ui::right_sidebar::{
@@ -21,7 +21,7 @@ use std::rc::Rc;
use wezterm_client::domain::FrontendRecoverySlot;
use wezterm_font::LoadedFont;
use window::color::LinearRgba;
-use window::{MouseEvent, MouseEventKind as WMEK, MousePress, WindowOps};
+use window::{MouseEvent, MouseEventKind as WMEK, MousePress, RectF, WindowOps};
/// An agent that is working, in the same blue the left sidebar uses for a
/// live thread (`SESSION_STATUS_OPEN_COLOR`).
@@ -35,7 +35,7 @@ pub(crate) const AGENT_BLOCKED_COLOR: LinearRgba = LinearRgba::with_components(0
pub(crate) const AGENT_DONE_COLOR: LinearRgba =
crate::termwindow::ui::sidebar::SESSION_STATUS_DONE_COLOR;
/// The progress bar under a row's description.
-const AGENT_PROGRESS_HEIGHT: usize = 6;
+pub(crate) const AGENT_PROGRESS_HEIGHT: usize = 6;
/// Between two agent rows; a hairline sits in the middle of it.
const AGENT_ROW_GAP: usize = 10;
/// How much further in than the panel's inset agent rows start and end.
@@ -481,35 +481,9 @@ impl TermWindow {
let title_y = top + (row_height.saturating_sub(cell_height * 2 + line_gap)) / 2;
let title_mid = title_y + cell_height / 2;
let icon_y = title_mid.saturating_sub(icon_size / 2);
+ let brand = brand_of(agent);
if visible(icon_y, icon_size) {
- match agent_status::brand_icon(
- &agent.agent_id,
- crate::native_settings::effective_appearance(),
- ) {
- Some(AgentIcon::Color(brand)) => self.paint_sidebar_brand_icon(
- layers,
- brand,
- icon_x,
- icon_y,
- icon_size,
- )?,
- Some(AgentIcon::Mono(icon)) => self.paint_sidebar_icon(
- layers,
- icon,
- icon_x,
- icon_y,
- icon_size,
- muted_fg,
- )?,
- None => self.paint_sidebar_icon(
- layers,
- SvgIcon::Bot,
- icon_x,
- icon_y,
- icon_size,
- muted_fg,
- )?,
- }
+ self.paint_agent_mark(layers, brand, icon_x, icon_y, icon_size, muted_fg)?;
}
let shown = agent.shown_state();
@@ -530,12 +504,7 @@ impl TermWindow {
let text_right = text_right_for(has_state_icon);
let text_width = text_right.saturating_sub(text_x);
- let name = agent_status::display_name(&agent.agent_id);
- let title_line = if agent.title.is_empty() {
- name
- } else {
- format!("{name} · {}", agent.title)
- };
+ let title_line = agent_row_title(agent, brand);
if visible(title_y, cell_height) {
self.paint_agent_text(
layers,
@@ -639,31 +608,18 @@ impl TermWindow {
};
if let Some(progress) = layout.progress {
if visible(line_y, bar_height) {
- let radius = bar_height as f32 / 2.0;
- self.fill_rounded_rectangle(
+ self.paint_agent_progress(
layers,
- 1,
euclid::rect(
text_x as f32,
line_y as f32,
text_width as f32,
bar_height as f32,
),
+ progress,
chrome.separator,
- radius,
- )
- .context("agent progress track")?;
- let filled = (text_width as f32 * f32::from(progress) / 100.0).round();
- if filled >= bar_height as f32 {
- self.fill_rounded_rectangle(
- layers,
- 1,
- euclid::rect(text_x as f32, line_y as f32, filled, bar_height as f32),
- chrome.accent,
- radius,
- )
- .context("agent progress")?;
- }
+ chrome.accent,
+ )?;
}
line_y += bar_height + line_gap;
}
@@ -706,11 +662,7 @@ impl TermWindow {
let mut args = fluent_bundle::FluentArgs::new();
args.set("count", layout.subtask_count);
let mut line = crate::i18n::tr_args("right-agents-subtasks", &args);
- let working = report
- .children
- .iter()
- .filter(|child| matches!(child.state, ProgramReportState::Working))
- .count();
+ let working = working_subtasks(report);
// Unless every sub-task has its dot in view, this line is
// all there is to say how many run: folded, or with some
// cut off below the list.
@@ -880,7 +832,7 @@ impl TermWindow {
/// One line of the panel in one colour. See `paint_agent_text_with`.
#[allow(clippy::too_many_arguments)]
- fn paint_agent_text(
+ pub(crate) fn paint_agent_text(
&self,
layers: &mut TripleLayerQuadAllocator,
font: &Rc<LoadedFont>,
@@ -1030,11 +982,57 @@ impl TermWindow {
Ok(fitted)
}
- /// The pill naming what a blocked program waits for. Returns where the
- /// text after it starts.
+ /// An agent's mark: its brand's when it has one, a robot when not.
+ pub(crate) fn paint_agent_mark(
+ &self,
+ layers: &mut TripleLayerQuadAllocator,
+ brand: Option<AgentIcon>,
+ x: usize,
+ y: usize,
+ size: usize,
+ mono: LinearRgba,
+ ) -> anyhow::Result<()> {
+ match brand {
+ Some(AgentIcon::Color(brand)) => {
+ self.paint_sidebar_brand_icon(layers, brand, x, y, size)
+ }
+ Some(AgentIcon::Mono(icon)) => self.paint_sidebar_icon(layers, icon, x, y, size, mono),
+ None => self.paint_sidebar_icon(layers, SvgIcon::Bot, x, y, size, mono),
+ }
+ }
+
+ /// A progress bar: its track, and the share done over it once that is
+ /// wide enough to show its rounded ends.
+ pub(crate) fn paint_agent_progress(
+ &self,
+ layers: &mut TripleLayerQuadAllocator,
+ rect: RectF,
+ progress: u8,
+ track: LinearRgba,
+ fill: LinearRgba,
+ ) -> anyhow::Result<()> {
+ let radius = rect.size.height / 2.0;
+ self.fill_rounded_rectangle(layers, 1, rect, track, radius)
+ .context("agent progress track")?;
+ let filled = (rect.size.width * f32::from(progress) / 100.0).round();
+ if filled >= rect.size.height {
+ self.fill_rounded_rectangle(
+ layers,
+ 1,
+ euclid::rect(rect.origin.x, rect.origin.y, filled, rect.size.height),
+ fill,
+ radius,
+ )
+ .context("agent progress")?;
+ }
+ Ok(())
+ }
+
+ /// The pill naming what a blocked program waits for, no wider than the
+ /// room up to `right`. Returns where the text after it starts.
#[allow(clippy::too_many_arguments)]
- fn paint_agent_kind_pill(
- &mut self,
+ pub(crate) fn paint_agent_kind_pill(
+ &self,
layers: &mut TripleLayerQuadAllocator,
ui_font: &Rc<LoadedFont>,
ui_metrics: RenderMetrics,
@@ -1602,7 +1600,7 @@ impl AgentRowLayout {
};
let message = (show.description && report.msg.is_some())
|| (show.reason && report.kind.is_some());
- let progress = report.progress.filter(|_| show.progress);
+ let progress = agent_status::report_progress(agent, show);
let subtask_count = if show.subtasks {
report.children.len()
} else {
@@ -1723,6 +1721,51 @@ impl ShimmerBand {
}
}
+/// An agent's title beside its mark. Its own mark already says which agent
+/// it is, so the room is the pane's title; beside the generic robot the name
+/// has to say it.
+pub(crate) fn agent_row_title(
+ agent: &agent_status::AgentPaneStatus,
+ brand: Option<AgentIcon>,
+) -> String {
+ if brand.is_none() && !agent.title.is_empty() {
+ format!(
+ "{} \u{b7} {}",
+ agent_status::display_name(&agent.agent_id),
+ agent.title
+ )
+ } else {
+ agent_title(agent)
+ }
+}
+
+/// An agent's title as its cards show it: what its pane is called, or the
+/// agent's own name when the pane has none.
+pub(crate) fn agent_title(agent: &agent_status::AgentPaneStatus) -> String {
+ if agent.title.is_empty() {
+ agent_status::display_name(&agent.agent_id)
+ } else {
+ agent.title.clone()
+ }
+}
+
+/// The agent's brand mark for the current theme, if it has one.
+pub(crate) fn brand_of(agent: &agent_status::AgentPaneStatus) -> Option<AgentIcon> {
+ agent_status::brand_icon(
+ &agent.agent_id,
+ crate::native_settings::effective_appearance(),
+ )
+}
+
+/// How many of a report's sub-tasks are working.
+pub(crate) fn working_subtasks(report: &ProgramReport) -> usize {
+ report
+ .children
+ .iter()
+ .filter(|child| matches!(child.state, ProgramReportState::Working))
+ .count()
+}
+
/// The icon a state is shown with: glyph, colour, and whether it spins.
pub(crate) fn agent_state_icon(
state: agent_status::ShownState,
diff --git a/wezterm-gui/src/workspace_threads.rs b/wezterm-gui/src/workspace_threads.rs
index 4efd7825..2c4671fd 100644
--- a/wezterm-gui/src/workspace_threads.rs
+++ b/wezterm-gui/src/workspace_threads.rs
@@ -2201,10 +2201,16 @@ pub fn thread_place_and_machine_for_workspace(workspace: &str) -> Option<(String
/// `origin_machine_for_project` names it; `None` for this device. Reads the
/// host list, so it is for menus rather than painting.
pub fn machine_label_for_workspace(workspace: &str) -> Option<String> {
+ thread_machine_label(workspace).flatten()
+}
+
+/// [`machine_label_for_workspace`], told apart from not knowing: `None`
+/// when no thread backs the workspace, `Some(None)` for this device.
+pub fn thread_machine_label(workspace: &str) -> Option<Option<String>> {
let store = THREAD_STORE.lock();
let (project, _) = project_and_thread_for_workspace(&store, workspace)?;
let (label, local) = origin_machine_for_project(project, &store.spaces);
- (!local).then_some(label)
+ Some((!local).then_some(label))
}
fn project_and_thread_for_workspace<'a>(