diff --git a/src/app/runtime.rs b/src/app/runtime.rs index 5bfa91417ae..a7295f4a5ab 100644 --- a/src/app/runtime.rs +++ b/src/app/runtime.rs @@ -311,12 +311,12 @@ impl App { .state .active .and_then(|idx| self.state.workspaces.get(idx)) - .is_some_and(|ws| ws.has_working_pane(&self.state.terminals)), + .is_some_and(|ws| ws.has_animated_pane(&self.state.terminals)), crate::app::state::AgentPanelScope::AllWorkspaces => self .state .workspaces .iter() - .any(|ws| ws.has_working_pane(&self.state.terminals)), + .any(|ws| ws.has_animated_pane(&self.state.terminals)), } } @@ -648,6 +648,34 @@ mod tests { (app, pane_id) } + #[test] + fn blocked_pane_keeps_agent_animation_timer_running() { + let (mut app, pane_id) = test_app_with_pane(); + app.state.ensure_test_terminals(); + let terminal_id = app.state.workspaces[0] + .pane_state(pane_id) + .expect("test pane should exist") + .attached_terminal_id + .clone(); + app.state + .terminals + .get_mut(&terminal_id) + .expect("test terminal should exist") + .state = crate::detect::AgentState::Blocked; + + assert!(app.agent_panel_has_animation()); + app.sync_animation_timer(Instant::now()); + assert!(app.next_animation_tick.is_some()); + + app.state + .terminals + .get_mut(&terminal_id) + .expect("test terminal should exist") + .state = crate::detect::AgentState::Idle; + app.sync_animation_timer(Instant::now()); + assert!(app.next_animation_tick.is_none()); + } + #[test] fn git_refresh_deduplicates_workspaces_with_same_cache_key() { let repo = diff --git a/src/ui.rs b/src/ui.rs index f6fc54d40cf..a07045fd9fe 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -92,11 +92,12 @@ const COLLAPSED_WIDTH: u16 = 4; // num + space + dot + separator // Braille spinner frames — smooth rotation const SPINNERS: &[&str] = &["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]; +const SPINNER_TICKS_PER_FRAME: u32 = 8; /// Map spinner_tick (incremented every frame at ~60fps) to a spinner frame. /// We want ~8 updates/sec so divide by 8. pub(super) fn spinner_frame(tick: u32) -> &'static str { - SPINNERS[(tick as usize / 8) % SPINNERS.len()] + SPINNERS[(tick as usize / SPINNER_TICKS_PER_FRAME as usize) % SPINNERS.len()] } /// Compute view geometry and reconcile pane sizes. diff --git a/src/ui/status.rs b/src/ui/status.rs index 8ec4f392feb..bafa92295dc 100644 --- a/src/ui/status.rs +++ b/src/ui/status.rs @@ -171,7 +171,14 @@ pub(super) fn agent_icon( p: &Palette, ) -> (&'static str, Style) { match (state, seen) { - (AgentState::Blocked, _) => ("◉", Style::default().fg(p.red)), + (AgentState::Blocked, _) => { + let icon = if (tick / super::SPINNER_TICKS_PER_FRAME).is_multiple_of(2) { + "◉" + } else { + "○" + }; + (icon, Style::default().fg(p.red)) + } (AgentState::Working, _) => (super::spinner_frame(tick), Style::default().fg(p.yellow)), (AgentState::Idle, false) => ("●", Style::default().fg(p.teal)), (AgentState::Idle, true) => ("✓", Style::default().fg(p.green)), @@ -198,3 +205,35 @@ pub(super) fn state_label_color(state: AgentState, seen: bool, p: &Palette) -> C (AgentState::Unknown, _) => p.overlay0, } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn blocked_agent_icon_alternates_with_spinner_tick() { + let palette = Palette::catppuccin(); + let (visible, visible_style) = agent_icon(AgentState::Blocked, true, 0, &palette); + let (hollow, hollow_style) = agent_icon(AgentState::Blocked, true, 8, &palette); + + assert_ne!(visible, hollow); + assert_eq!(visible_style.fg, Some(palette.red)); + assert_eq!(hollow_style.fg, Some(palette.red)); + } + + #[test] + fn non_blocked_agent_icons_keep_existing_rendering() { + let palette = Palette::catppuccin(); + + assert_eq!(agent_icon(AgentState::Working, true, 0, &palette).0, "⠋"); + assert_eq!(agent_icon(AgentState::Working, true, 8, &palette).0, "⠙"); + for (state, seen, expected) in [ + (AgentState::Idle, false, "●"), + (AgentState::Idle, true, "✓"), + (AgentState::Unknown, true, "○"), + ] { + assert_eq!(agent_icon(state, seen, 0, &palette).0, expected); + assert_eq!(agent_icon(state, seen, 1, &palette).0, expected); + } + } +} diff --git a/src/workspace/aggregate.rs b/src/workspace/aggregate.rs index c9c1266dfbe..f55044493e6 100644 --- a/src/workspace/aggregate.rs +++ b/src/workspace/aggregate.rs @@ -22,11 +22,13 @@ pub struct PaneDetail { } impl Tab { - pub fn has_working_pane(&self, terminals: &HashMap) -> bool { + pub fn has_animated_pane(&self, terminals: &HashMap) -> bool { self.panes.values().any(|pane| { terminals .get(&pane.attached_terminal_id) - .is_some_and(|terminal| terminal.state == AgentState::Working) + .is_some_and(|terminal| { + matches!(terminal.state, AgentState::Working | AgentState::Blocked) + }) }) } @@ -90,8 +92,8 @@ impl Workspace { .unwrap_or((AgentState::Unknown, true)) } - pub fn has_working_pane(&self, terminals: &HashMap) -> bool { - self.tabs.iter().any(|tab| tab.has_working_pane(terminals)) + pub fn has_animated_pane(&self, terminals: &HashMap) -> bool { + self.tabs.iter().any(|tab| tab.has_animated_pane(terminals)) } pub fn pane_details(&self, terminals: &HashMap) -> Vec {