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
6 changes: 1 addition & 5 deletions src/app/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,7 @@ impl Workspace {
let cwd = self.new_session_cwd();
self.act(Act::NewClaude { cwd })
}
Command::ToggleShell => {
if let Some(id) = self.active.clone() {
self.act(Act::ToggleShell(id))
}
}
Command::ToggleShell => self.toggle_shell_here(),
Command::CloseSession => {
if let Some(id) = self.active.clone() {
self.act(Act::CloseLive(id))
Expand Down
34 changes: 34 additions & 0 deletions src/app/headless.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,40 @@ fn antigravity_limits_show_one_row_per_pool_only_with_antigravity_subagents_on()
assert!(h.drawn("meter-logo-antigravity-0") && h.drawn("meter-logo-antigravity-1"), "each pool's row starts with its logos");
}

/// The welcome screen has a shell of its own: it opens with no session, takes the keyboard, is resized like any
/// shell, hides while a session is shown, and is back when the last session closes.
#[test]
fn the_shell_opens_on_the_welcome_screen() {
let mut h = Harness::new(|_| vec![]);
assert!(h.ws().main == Main::Home && h.ws().active.is_none(), "starts on the welcome screen");
h.step(|ws| ws.command(Command::ToggleShell));
h.settle();
assert!(h.ws().shells.get(HOME_SHELL).is_some_and(|p| p.open), "the shell opens with no session");
assert!(h.ws().terminal_focused(&shell_key(HOME_SHELL)), "it takes the keyboard");
assert!(h.drawn("shell-panel"), "the shell panel draws: {:?}", h.keys());
h.step(|ws| {
ws.shell_drag = Some(SideDrag { size: SHELL_HEIGHT });
ws.drag_shell(-100.0);
assert_eq!(ws.shells[HOME_SHELL].height, SHELL_HEIGHT + 100.0, "the divider resizes it");
ws.shell_drag = None;
});

// A session shown hides it, and it keeps running; the session's own shell is separate.
let cwd = h.work.clone();
h.step(|ws| ws.new_claude(cwd.clone()));
let id = h.ws().active.clone().expect("a session is shown");
h.settle();
assert!(!h.drawn("shell-panel"), "the welcome shell stays out of a session's view");
assert!(h.ws().shells.contains_key(HOME_SHELL), "but is kept");
h.step(|ws| ws.close_live(&id));
h.settle();
assert!(h.ws().main == Main::Home && h.drawn("shell-panel"), "closing the last session brings the welcome shell back");
assert!(h.ws().terminal_focused(&shell_key(HOME_SHELL)), "and the keyboard with it");

h.step(|ws| ws.command(Command::ToggleShell));
assert!(!h.ws().shells[HOME_SHELL].open, "toggled shut");
}

/// Sessions and the shell under them, the sidebars' widths, cards and the GitHub view, with a stand-in `claude`.
#[test]
fn sessions_and_the_shell_panel() {
Expand Down
5 changes: 4 additions & 1 deletion src/app/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,10 @@ impl Workspace {
pub fn poll(&mut self, tx: &mut Tx) -> bool {
let mut changed = self.run_jobs();
changed |= std::mem::take(&mut self.rt.dirty);
let showing = if self.main == Main::Terminals { self.active.clone() } else { None };
let showing = match self.main {
Main::Terminals => self.active.clone(),
Main::Home => Some(HOME_SHELL.to_string()),
};
let foreground = self.window_active;
let mut next: Option<Instant> = None;
let mut pump = |view: &mut TerminalView, visible: bool| -> bool {
Expand Down
36 changes: 33 additions & 3 deletions src/app/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,34 @@ impl Workspace {
self.focus_shell();
}

/// Show or hide the shell of what is on screen: the shown session's, or on the welcome screen the one that needs
/// no session. It starts in the home folder and is kept while sessions are open.
pub fn toggle_shell_here(&mut self) {
if let Some(id) = self.active_id().cloned() {
self.toggle_shell(&id);
return;
}
if let Some(p) = self.shells.get_mut(HOME_SHELL) {
p.open = !p.open;
} else if let Some(cwd) = platform::home_dir() {
let panel = self.new_shell_panel(HOME_SHELL, cwd);
self.shells.insert(HOME_SHELL.to_string(), panel);
} else {
self.toast("Could not find the home folder for a shell.", true);
return;
}
if self.shells.get(HOME_SHELL).is_some_and(|p| p.open) {
self.focus_shell();
} else {
self.focus_active();
}
}

/// The owner of the shell panel on screen: the shown session, or `HOME_SHELL` on the welcome screen.
pub fn shell_owner(&self) -> Id {
self.active_id().cloned().unwrap_or_else(|| HOME_SHELL.to_string())
}

/// A shell for the session, started in `cwd`. When the shell ends, its panel goes away (`on_terminal_event`), with a
/// toast if it never started.
pub(super) fn new_shell_panel(&mut self, id: &str, cwd: PathBuf) -> ShellPanel {
Expand All @@ -41,8 +69,9 @@ impl Workspace {
}

fn focus_shell(&mut self) {
if let Some(id) = self.active_id().filter(|id| self.shells.get(*id).is_some_and(|p| p.open)).cloned() {
self.focus_terminal(&shell_key(&id));
let owner = self.shell_owner();
if self.shells.get(&owner).is_some_and(|p| p.open) {
self.focus_terminal(&shell_key(&owner));
}
}

Expand All @@ -64,7 +93,8 @@ impl Workspace {
let Some(d) = self.shell_drag else { return };
let window_h = self.window_size.1;
let height = (d.size - dy).clamp(SHELL_MIN, (window_h - 200.0).max(SHELL_MIN));
if let Some(p) = self.active.clone().and_then(|id| self.shells.get_mut(&id)) {
let owner = self.shell_owner();
if let Some(p) = self.shells.get_mut(&owner) {
p.height = height;
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,9 @@ pub fn shell_key(id: &str) -> String {
format!("shell:{id}")
}

/// The owner of the shell on the welcome screen, which has no session. Session ids are UUIDs, so it never collides.
pub const HOME_SHELL: &str = "home";

pub const SHELL_HEIGHT: f32 = 260.0;
pub const SHELL_MIN: f32 = 120.0;

Expand Down
7 changes: 4 additions & 3 deletions src/app/sessions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,12 +302,12 @@ impl Workspace {
self.prune_live();
}

/// Exited terminals are only kept while shown; a shell panel goes with its session.
/// Exited terminals are only kept while shown; a shell panel goes with its session, except the welcome screen's.
fn prune_live(&mut self) {
let active = &self.active;
self.live.retain(|l| active.as_ref() == Some(&l.id) || l.view.is_running());
let live = &self.live;
self.shells.retain(|id, _| live.iter().any(|l| &l.id == id));
self.shells.retain(|id, _| id == HOME_SHELL || live.iter().any(|l| &l.id == id));
}

/// A Claude session that never produced a transcript (opened and closed without a prompt) has nothing
Expand Down Expand Up @@ -383,10 +383,11 @@ impl Workspace {
}
}

/// Give the keyboard to the shown session's terminal, or to nothing on the home page.
/// Give the keyboard to the shown session's terminal, or on the home page to its shell when one is open.
pub fn focus_active(&mut self) {
match (self.main, self.active.clone()) {
(Main::Terminals, Some(id)) if self.live_view(&id).is_some() => self.focus_terminal(&id),
(Main::Home, _) if self.shells.get(HOME_SHELL).is_some_and(|p| p.open) => self.focus_terminal(&shell_key(HOME_SHELL)),
_ => {
self.keys_to = None;
self.blur = true;
Expand Down
21 changes: 7 additions & 14 deletions src/panels/workspace_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,16 +128,10 @@ impl Workspace {
if hints {
right = right.child(key_hint("J").key("hint-shell"));
}
right = right.child(if session_active {
icon_button(&icons::PANEL_BOTTOM).key("toggle-shell").help("Shell").on_press_tx(|ws: &mut Workspace, tx: &mut Tx| {
if let Some(id) = ws.active.clone() {
ws.act(Act::ToggleShell(id));
}
ws.after_input(tx);
})
} else {
icon_button_disabled(&icons::PANEL_BOTTOM).key("toggle-shell")
});
right = right.child(icon_button(&icons::PANEL_BOTTOM).key("toggle-shell").help("Shell").on_press_tx(|ws: &mut Workspace, tx: &mut Tx| {
ws.toggle_shell_here();
ws.after_input(tx);
}));
if hints {
right = right.child(key_hint("Shift+R").key("hint-right"));
}
Expand Down Expand Up @@ -208,9 +202,8 @@ impl Workspace {
/// The session's shell as its own panel under the main one: same gutter, rounding and grip as the sidebars. It
/// slides up from the bottom edge.
fn render_shell(&self) -> El {
let shown = self.active.clone().filter(|_| self.main == Main::Terminals);
let panel = shown.as_ref().and_then(|id| self.shells.get(id).map(|p| (id.clone(), p)));
let Some((id, p)) = panel else { return el().key("shell-slot").h(0.0) };
let id = self.shell_owner();
let Some(p) = self.shells.get(&id) else { return el().key("shell-slot").h(0.0) };
let height = if p.open { p.height } else { 0.0 };
let key = crate::app::shell_key(&id);
let focused = self.terminal_focused(&key);
Expand All @@ -226,7 +219,7 @@ impl Workspace {
.on_drag(|ws: &mut Workspace, d: &mut rune::Drag, tx: &mut Tx| {
match d.phase {
Phase::Down => {
let height = ws.active.as_ref().and_then(|id| ws.shells.get(id)).map_or(SHELL_HEIGHT, |p| p.height);
let height = ws.shells.get(&ws.shell_owner()).map_or(SHELL_HEIGHT, |p| p.height);
ws.shell_drag = Some(SideDrag { size: height });
}
Phase::Move => ws.drag_shell(d.dy),
Expand Down
Loading