Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 58 additions & 19 deletions src/app/background.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@

use super::*;

/// What a Claude session's row shows, given what Claude Code says it is doing, what the row showed before, and
/// whether the user is looking at it. A question is shown even to someone looking at it, since only they can answer;
/// a finished turn is shown only to someone who was elsewhere and clears once they look.
fn next_activity(working: bool, waiting: bool, before: Option<Activity>, viewing: bool) -> Option<Activity> {
match (working, waiting, before) {
(true, _, _) => Some(Activity::Working),
(false, true, _) => Some(Activity::Waiting),
(false, false, Some(Activity::Working | Activity::Attention)) if !viewing => Some(Activity::Attention),
_ => None,
}
}

impl Workspace {
/// Startup reconciliation: scan Claude Code's records off the UI thread, then merge.
pub fn start_scan(&mut self, cx: &mut Context<Self>) {
Expand Down Expand Up @@ -46,21 +58,21 @@ impl Workspace {
.detach();
}

/// While a session works, its sidebar dot pulses: the session list is redrawn a few times a second (with the
/// While a session works, its sidebar icon spins: the session list is redrawn many times a second (with the
/// window's top level, which reuses the other cached parts). It stops once nothing works.
fn start_pulse(&mut self, cx: &mut Context<Self>) {
if self.pulsing {
fn start_spin(&mut self, cx: &mut Context<Self>) {
if self.spinning {
return;
}
self.pulsing = true;
self.spinning = true;
cx.spawn(async move |this, cx| {
loop {
cx.background_executor().timer(crate::panels::sidebar::PULSE_STEP).await;
cx.background_executor().timer(crate::panels::status_icon::SPIN_STEP).await;
let working = this.update(cx, |ws, cx| {
let working = ws.activity.values().any(|a| *a == Activity::Working);
match &ws.session_list {
Some(list) if working => list.update(cx, |_, cx| cx.notify()),
_ => ws.pulsing = working,
_ => ws.spinning = working,
}
working
});
Expand Down Expand Up @@ -118,26 +130,20 @@ impl Workspace {
let viewing = window_active && shown.as_deref() == Some(l.id.as_str());
let status = self.store.session(&l.id).and_then(|r| statuses.get(r.claude_id()?));
let working = status.map_or_else(|| view.is_working(), |s| s == "busy");
match (working, self.activity.get(&l.id)) {
(true, _) => {
next.insert(l.id.clone(), Activity::Working);
}
(false, Some(Activity::Working)) if !viewing => {
flash |= !window_active;
next.insert(l.id.clone(), Activity::Attention);
}
(false, Some(Activity::Attention)) if !viewing => {
next.insert(l.id.clone(), Activity::Attention);
}
_ => {}
let waiting = status.is_some_and(|s| s == "waiting");
let before = self.activity.get(&l.id).copied();
let now = next_activity(working, waiting, before, viewing);
flash |= !window_active && before == Some(Activity::Working) && matches!(now, Some(Activity::Attention | Activity::Waiting));
if let Some(now) = now {
next.insert(l.id.clone(), now);
}
}
if next != self.activity {
self.activity = next;
cx.notify();
}
if self.activity.values().any(|a| *a == Activity::Working) {
self.start_pulse(cx);
self.start_spin(cx);
}
if flash {
platform::request_attention(window);
Expand Down Expand Up @@ -287,3 +293,36 @@ impl Workspace {
crate::updater::check(self, cx);
}
}

#[cfg(test)]
mod tests {
use super::{Activity, next_activity};

#[test]
fn busy_is_working_whatever_came_before() {
for before in [None, Some(Activity::Working), Some(Activity::Waiting), Some(Activity::Attention)] {
assert_eq!(next_activity(true, false, before, true), Some(Activity::Working));
assert_eq!(next_activity(true, false, before, false), Some(Activity::Working));
}
}

#[test]
fn a_question_shows_even_to_someone_looking_at_the_session() {
assert_eq!(next_activity(false, true, Some(Activity::Working), true), Some(Activity::Waiting));
assert_eq!(next_activity(false, true, None, false), Some(Activity::Waiting));
}

#[test]
fn a_finished_turn_waits_to_be_seen_and_clears_once_looked_at() {
assert_eq!(next_activity(false, false, Some(Activity::Working), false), Some(Activity::Attention));
assert_eq!(next_activity(false, false, Some(Activity::Attention), false), Some(Activity::Attention));
assert_eq!(next_activity(false, false, Some(Activity::Working), true), None);
assert_eq!(next_activity(false, false, Some(Activity::Attention), true), None);
}

#[test]
fn an_idle_session_nobody_is_owed_news_from_shows_nothing() {
assert_eq!(next_activity(false, false, None, false), None);
assert_eq!(next_activity(false, false, Some(Activity::Waiting), false), None);
}
}
19 changes: 13 additions & 6 deletions src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,14 +223,16 @@ pub enum Act {
impl MenuItem {
/// A plain entry: not dangerous, enabled, no hint, no separator above.
pub fn new(label: impl Into<String>, act: Act) -> Self {
Self { label: label.into(), hint: None, act, danger: false, disabled: false, separator_before: false, remove: None, icon: None }
Self { label: label.into(), hint: None, detail: None, act, danger: false, disabled: false, separator_before: false, remove: None, icon: None }
}
}

pub struct MenuItem {
pub label: String,
/// Faint text on the right that is never cut, so a long `label` is shortened with "…" instead.
pub hint: Option<String>,
/// Faint second line under the label, for text too long to sit beside it (a project path).
pub detail: Option<String>,
pub act: Act,
pub danger: bool,
/// Shown greyed out and does nothing when clicked.
Expand Down Expand Up @@ -312,9 +314,11 @@ pub enum Main {
/// What a running Claude session is doing, as shown by its sidebar dot.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Activity {
/// Output is streaming (pulsing dot).
/// Output is streaming (spinning icon).
Working,
/// Finished working while the user was looking elsewhere (orange dot).
/// Claude Code stopped to wait for the user, a question or a permission (question mark).
Waiting,
/// Finished working while the user was looking elsewhere (check mark).
Attention,
}

Expand Down Expand Up @@ -478,10 +482,12 @@ pub struct Workspace {
pub list_model: crate::panels::sidebar::ListModel,
/// The sidebar row under the pointer, the only one built with its × or archive button.
pub hovered_row: Option<gpui::SharedString>,
/// Running rows the pointer just left, whose × slot is still shrinking away (see `shrink_close_slot`).
pub unhovered_rows: std::collections::HashSet<gpui::SharedString>,
/// The minute (Unix time / 60) of the last tick's redraw, see `tick`.
pub tick_minute: i64,
/// The working dot's pulse is running, see `start_pulse`.
pub pulsing: bool,
/// The working icon's spin is running, see `start_spin`.
pub spinning: bool,
/// When a drag last reordered the sidebar, see `pointer_moved`.
pub last_swap: std::time::Instant,
/// Attached issues and pull requests are asked about on GitHub from time to time, see `attached_sync.rs`.
Expand Down Expand Up @@ -585,8 +591,9 @@ impl Workspace {
session_list: None,
list_model: Default::default(),
hovered_row: None,
unhovered_rows: Default::default(),
tick_minute: 0,
pulsing: false,
spinning: false,
last_swap: std::time::Instant::now(),
attached_sync: Default::default(),
config_sync: Default::default(),
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ gpui_kit::assets::icon_assets!(
AppIcons,
[
WindowMinimize, WindowMaximize, WindowRestore, WindowClose, Archive, ArchiveRestore, ArrowDownToLine, ArrowLeft, Brackets, Check, ChevronDown, ChevronRight,
CircleCheck, CircleDot, CircleSlash, CircleX, Clock, Ellipsis, Eye, ExternalLink, File, FileText, Folder, FolderGit2, FolderOpen, GitBranch, GitCommitHorizontal, GitMerge, GitPullRequest,
CircleCheck, CircleDot, CircleDotDashed, CircleQuestionMark, CircleSlash, CircleSmall, CircleX, Clock, Ellipsis, Eye, ExternalLink, File, FileText, Folder, FolderGit2, FolderOpen, GitBranch, GitCommitHorizontal, GitMerge, GitPullRequest,
GitPullRequestClosed, GitPullRequestDraft, HeartPlus, LoaderCircle, Lock, MessageSquare, FileCode, PanelBottom, PanelLeft, PanelRight, Pencil, RefreshCw, Search,
Settings, Terminal, X
]
Expand Down
3 changes: 2 additions & 1 deletion src/panels/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
//! What Claudiu draws around the terminals. `workspace_view` is the root view (main area, overlays, toasts), `sidebar`
//! and `inspector` are the two side panels, `editor_pane` is editor mode's files and editor, `widgets` holds the small
//! shared pieces. `theme` and `scale` set the look, and `glide` does the smooth scrolling.
//! shared pieces, `status_icon` the icon at the start of a session row. `theme` and `scale` set the look, and `glide` does the smooth scrolling.

pub mod editor_pane;
pub mod glide;
pub mod inspector;
pub mod scale;
pub mod sidebar;
pub mod status_icon;
pub mod theme;
pub mod widgets;
pub mod workspace_view;
Loading
Loading