Close workspace windows when their final tab disappears

This commit is contained in:
James Magahern
2026-11-17 18:13:06 -08:00
parent 0f272d5298
commit 119df745fc
3 changed files with 20 additions and 16 deletions
+3 -2
View File
@@ -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. expanded, and their output does not redraw unchanged visible grids.
When a shell exits, its pane closes automatically. An empty tab closes too, 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 and focus moves to an adjacent remaining pane or tab when needed. When the
last shell exits, the window stays open with `+` available to start another tab. 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 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 to the same session share those and the underlying PTY grid. Each window keeps
+1 -1
View File
@@ -2467,7 +2467,7 @@ mod tests {
let empty = snapshot(&mut client, |s| s.tabs.is_empty()); let empty = snapshot(&mut client, |s| s.tabs.is_empty());
assert!(empty.panes.is_empty()); assert!(empty.panes.is_empty());
assert_eq!(empty.active_tab, 0); 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); send(&mut client, ClientMessage::Ping);
loop { loop {
if matches!( if matches!(
+16 -13
View File
@@ -388,6 +388,11 @@ impl Workspace {
view.error = Some(error); view.error = Some(error);
} }
if let Some(snapshot) = update.snapshot { 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| { let metadata_changed = view.snapshot.as_ref().is_none_or(|old| {
old.active_tab != snapshot.active_tab old.active_tab != snapshot.active_tab
|| old.tabs != snapshot.tabs || old.tabs != snapshot.tabs
@@ -618,19 +623,17 @@ impl Render for Workspace {
let mut incoming = scene(incoming_offset).id("incoming-scene"); let mut incoming = scene(incoming_offset).id("incoming-scene");
if let Some(snapshot) = &self.snapshot { if let Some(snapshot) = &self.snapshot {
incoming = pane_scene(snapshot, &self.panes, incoming_offset, Some(&self.client)); incoming = pane_scene(snapshot, &self.panes, incoming_offset, Some(&self.client));
if snapshot.panes.is_empty() { if let Some(host) = snapshot
let status = match snapshot.active_tab() { .active_tab()
Some(tab) if tab.is_connecting() => tab .filter(|tab| tab.is_connecting())
.remote .and_then(|tab| tab.remote.as_ref())
.as_ref() {
.map(|host| format!("Connecting to {host}…")), incoming = incoming.child(
Some(_) => None, // The selected tab's grid is still in transit. div()
None => Some("No sessions. Use + to open a terminal.".to_owned()), .p_4()
}; .text_color(rgb(chrome::MUTED))
if let Some(status) = status { .child(format!("Connecting to {host}…")),
incoming = );
incoming.child(div().p_4().text_color(rgb(chrome::MUTED)).child(status));
}
} }
} else { } else {
incoming = incoming.child( incoming = incoming.child(