From 119df745fc183ef7952f33e255cb1374bbd236d3 Mon Sep 17 00:00:00 2001 From: James Magahern Date: Tue, 17 Nov 2026 18:13:06 -0800 Subject: [PATCH] Close workspace windows when their final tab disappears --- README.md | 5 +++-- src/server.rs | 2 +- src/terminal.rs | 29 ++++++++++++++++------------- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index cb9b9ce..f949849 100644 --- a/README.md +++ b/README.md @@ -277,8 +277,9 @@ GUI detach/reattach. Collapsed shells keep running; their grids are sent only wh expanded, and their output does not redraw unchanged visible grids. When a shell exits, its pane closes automatically. An empty tab closes too, -and focus moves to an adjacent remaining pane or tab when needed. After the -last shell exits, the window stays open with `+` available to start another tab. +and focus moves to an adjacent remaining pane or tab when needed. When the +last pane exits or the last tab closes, every window showing that session +closes. Windows showing other sessions stay open. Each session has its own tabs, panes, focus, and scrollback. Windows attached to the same session share those and the underlying PTY grid. Each window keeps diff --git a/src/server.rs b/src/server.rs index 5772c1b..b7d78f4 100644 --- a/src/server.rs +++ b/src/server.rs @@ -2467,7 +2467,7 @@ mod tests { let empty = snapshot(&mut client, |s| s.tabs.is_empty()); assert!(empty.panes.is_empty()); assert_eq!(empty.active_tab, 0); - // Removing the final shell leaves this GUI attached to a live server. + // Protocol clients that stay connected after the empty snapshot can start a new tab. send(&mut client, ClientMessage::Ping); loop { if matches!( diff --git a/src/terminal.rs b/src/terminal.rs index e6f0b21..44376ca 100644 --- a/src/terminal.rs +++ b/src/terminal.rs @@ -388,6 +388,11 @@ impl Workspace { view.error = Some(error); } if let Some(snapshot) = update.snapshot { + // A remote tab can still be connecting with no visible panes. + if snapshot.tabs.is_empty() { + window.remove_window(); + return; + } let metadata_changed = view.snapshot.as_ref().is_none_or(|old| { old.active_tab != snapshot.active_tab || old.tabs != snapshot.tabs @@ -618,19 +623,17 @@ impl Render for Workspace { let mut incoming = scene(incoming_offset).id("incoming-scene"); if let Some(snapshot) = &self.snapshot { incoming = pane_scene(snapshot, &self.panes, incoming_offset, Some(&self.client)); - if snapshot.panes.is_empty() { - let status = match snapshot.active_tab() { - Some(tab) if tab.is_connecting() => tab - .remote - .as_ref() - .map(|host| format!("Connecting to {host}…")), - Some(_) => None, // The selected tab's grid is still in transit. - None => Some("No sessions. Use + to open a terminal.".to_owned()), - }; - if let Some(status) = status { - incoming = - incoming.child(div().p_4().text_color(rgb(chrome::MUTED)).child(status)); - } + if let Some(host) = snapshot + .active_tab() + .filter(|tab| tab.is_connecting()) + .and_then(|tab| tab.remote.as_ref()) + { + incoming = incoming.child( + div() + .p_4() + .text_color(rgb(chrome::MUTED)) + .child(format!("Connecting to {host}…")), + ); } } else { incoming = incoming.child(