From a74306c40f80a107888bad8dee4931c44c992e6e Mon Sep 17 00:00:00 2001 From: ForeverInLaw <44206490+ForeverInLaw@users.noreply.github.com> Date: Tue, 1 Dec 2026 00:30:42 +0000 Subject: [PATCH 001/160] workspace: move the tab bar, sidebar and status bar into their own modules --- crates/redshell-app/src/sidebar.rs | 273 +++++++++++++ crates/redshell-app/src/status_bar.rs | 78 ++++ crates/redshell-app/src/tab_bar.rs | 197 ++++++++++ crates/redshell-app/src/workspace.rs | 539 +------------------------- 4 files changed, 554 insertions(+), 533 deletions(-) create mode 100644 crates/redshell-app/src/sidebar.rs create mode 100644 crates/redshell-app/src/status_bar.rs create mode 100644 crates/redshell-app/src/tab_bar.rs diff --git a/crates/redshell-app/src/sidebar.rs b/crates/redshell-app/src/sidebar.rs new file mode 100644 index 0000000..2fd84cf --- /dev/null +++ b/crates/redshell-app/src/sidebar.rs @@ -0,0 +1,273 @@ +//! The sidebar: open sessions, launch profiles, hosts, multiplexer sessions and recent history. + +use super::*; + +impl Workspace { + pub(super) fn render_sidebar(&self, cx: &mut Context) -> impl IntoElement + use<> { + let t = cx.theme().clone(); + let ui = *t.ui(); + let state = cx.global::(); + let width = px(state.settings.appearance.sidebar_width); + let recording = state.history.is_some(); + + let open_tabs = self + .tabs + .iter() + .enumerate() + .map(|(i, tab)| { + let tab_id = tab.id; + let v = tab.active.read(cx); + let sub = v.cwd.clone().unwrap_or_else(|| v.profile.description.clone()); + ListItem::new(("side-tab", tab.id), v.title()) + .icon(v.kind().into()) + .subtitle(sub) + .dense(true) + .selected(i == self.active) + .when(i != self.active && tab.views().iter().any(|v| v.read(cx).has_activity), |l| { + l.end(div().size(px(6.)).rounded_full().bg(ui.primary)) + }) + .on_click(cx.listener(move |this, _, w, cx| this.activate_tab_id(tab_id, w, cx))) + }) + .collect::>(); + + let launch_row = |p: LaunchProfile, cx: &mut Context| { + let id = SharedString::from(format!("side-{}", p.id)); + let available = p.available; + ListItem::new(id, p.name.clone()) + .icon(p.kind.into()) + .subtitle(p.description.clone()) + .dense(true) + .dimmed(!available) + .on_click(cx.listener(move |this, _, w, cx| this.open_profile(p.clone(), w, cx))) + }; + + let shells: Vec = state + .all_profiles() + .into_iter() + .filter(|p| matches!(p.kind, LaunchKind::Shell | LaunchKind::Plugin)) + .collect(); + let (agents, missing_agents): (Vec<_>, Vec<_>) = + state.profiles_of(LaunchKind::Agent).into_iter().partition(|p| p.available); + let missing_agents = missing_agents.len(); + let history_on = state.settings.history.enabled; + let hosts = state.profiles_of(LaunchKind::Ssh); + let mux_program = state.local_mux().mux.program(); + let mux_sessions = self.mux_cache.clone(); + let recent = self.recent.clone(); + + let shell_rows: Vec<_> = shells.into_iter().map(|p| launch_row(p, cx)).collect(); + let agent_rows: Vec<_> = agents.into_iter().map(|p| launch_row(p, cx)).collect(); + let has_agents = !agent_rows.is_empty(); + let host_rows: Vec<_> = hosts.into_iter().map(|p| launch_row(p, cx)).collect(); + let mux_rows: Vec<_> = mux_sessions + .into_iter() + .map(|s| { + let name = s.name.clone(); + ListItem::new(SharedString::from(format!("mux-{}", s.name)), s.name.clone()) + .icon(IconName::LayoutGrid) + .subtitle(format!( + "{} window{}{}", + s.windows, + if s.windows == 1 { "" } else { "s" }, + if s.attached { " · attached" } else { "" } + )) + .dense(true) + .on_click(cx.listener(move |this, _, w, cx| { + let p = cx.global::().local_mux().attach_profile(&name); + this.open_profile(p, w, cx); + })) + }) + .collect(); + let open_now = self.open_sessions(cx); + let recent_rows: Vec<_> = recent_entries(recent, &open_now) + .into_iter() + .map(|r| { + let id = r.id; + ListItem::new(SharedString::from(format!("recent-{}", r.id)), r.title.clone()) + .icon(IconName::History) + .subtitle(format!("{} · {}", r.profile.name, r.started().format("%b %d %H:%M"))) + .dense(true) + .on_click(cx.listener(move |this, _, w, cx| this.open_recording(id, false, w, cx))) + }) + .collect(); + + let header_button = |id: &'static str, icon: IconName, cmd: &'static str, cx: &mut Context| { + Button::new(id) + .icon(icon) + .size(ButtonSize::Xs) + .variant(ButtonVariant::Ghost) + .on_click(cx.listener(move |this, _, w, cx| this.run_command(cmd, w, cx))) + }; + let section = |label: &str, action: Option, cx: &App| { + let t = cx.theme(); + div() + .flex() + .items_center() + .justify_between() + .h(px(24.)) + .mt(px(10.)) + .mb(px(2.)) + .pl(px(10.)) + .pr(px(4.)) + .text_size(t.text_xs()) + .font_weight(FontWeight::SEMIBOLD) + .text_color(t.ui().muted_foreground) + .child(label.to_uppercase()) + .children(action) + }; + + div() + .flex() + .flex_col() + .flex_none() + .w(width) + .h_full() + .bg(ui.sidebar) + .text_color(ui.sidebar_foreground) + .border_r_1() + .border_color(ui.sidebar_border) + .child( + div() + .flex() + .items_center() + .gap(px(8.)) + .h(px(40.)) + .px(px(14.)) + .border_b_1() + .border_color(ui.sidebar_border) + .child(div().size(px(10.)).rounded_full().bg(ui.primary).shadow_sm()) + .child(div().flex_1().font_weight(FontWeight::BOLD).text_size(t.ui_size + px(1.)).child("RedShell")) + .when(recording, |d| d.child(Badge::new("● rec").variant(BadgeVariant::Primary))) + .child(header_button("side-search", IconName::Search, "session.search", cx)) + .child(header_button("side-settings", IconName::Settings, "settings.open", cx)), + ) + .child( + div() + .id("sidebar-scroll") + .flex_1() + .overflow_y_scroll() + .px(px(6.)) + .pb(px(12.)) + .child(section("Open sessions", None, cx)) + .children(open_tabs) + .child(section("Shells", None, cx)) + .children(shell_rows) + .child(section( + "AI agents", + Some(header_button("side-agent", IconName::Plus, "agent.launch", cx).into_any_element()), + cx, + )) + .when(agent_rows.is_empty(), |d| { + d.child(sidebar_hint( + "No AI coding agents found on PATH.", + Some(hint_button("hint-agents", "See install commands", "agent.launch", cx)), + cx, + )) + }) + .children(agent_rows) + .when(has_agents && missing_agents > 0, |d| { + d.child(sidebar_hint( + "", + Some(hint_button( + "hint-more-agents", + &format!("{missing_agents} more you can install…"), + "agent.launch", + cx, + )), + cx, + )) + }) + .child(section( + "SSH hosts", + Some(header_button("side-ssh", IconName::Plus, "ssh.connect", cx).into_any_element()), + cx, + )) + .children(host_rows) + .when(host_rows_empty(cx), |d| { + d.child(sidebar_hint( + "Hosts come from ~/.ssh/config and [[ssh.hosts]] in config.toml.", + Some(hint_button("hint-ssh", "Add a host in config.toml", "settings.edit_file", cx)), + cx, + )) + }) + .child(section( + mux_program, + Some(header_button("side-mux", IconName::Ellipsis, "mux.manage", cx).into_any_element()), + cx, + )) + .children(mux_rows) + .child(section( + "Recent", + Some(header_button("side-hist", IconName::Ellipsis, "session.history", cx).into_any_element()), + cx, + )) + .when(!history_on, |d| { + d.child(sidebar_hint( + "Recording is off: sessions are not saved or searchable.", + Some( + Button::new("hint-history") + .label("Turn on recording") + .size(ButtonSize::Xs) + .variant(ButtonVariant::Outline) + .on_click(cx.listener(|this, _, _, cx| { + update_settings(cx, |s| s.history.enabled = true); + this.toasts.push( + ToastKind::Success, + "Recording turned on", + Some("New sessions are recorded after RedShell restarts.".into()), + ); + cx.notify(); + })), + ), + cx, + )) + }) + .when(history_on && recent_rows.is_empty(), |d| { + d.child(sidebar_hint("Closed sessions are listed here, ready to view or restore.", None, cx)) + }) + .children(recent_rows), + ) + } +} + +/// The sidebar's Recent list: sessions not open in a tab, newest first, with +/// repeats of the same title and folder collapsed into the newest one. +fn recent_entries(records: Vec, open: &HashSet) -> Vec { + let mut seen = HashSet::new(); + records + .into_iter() + .filter(|r| !open.contains(&r.id)) + .filter(|r| seen.insert((r.title.clone(), r.cwd.clone(), r.profile.id.clone()))) + .take(6) + .collect() +} + +/// Muted explanatory text with an optional action, for empty sidebar sections. +fn sidebar_hint(text: &str, action: Option