Create independent sessions and open SSH sessions in adjacent tabs

Start new windows with a fresh shell and add explicit session selection through --attach. Route in-pane SSH launches back to the originating session, preserving remote shells and tab order across local detach and reattach.
This commit is contained in:
James Magahern
2026-11-17 14:50:29 -08:00
parent 10fa542937
commit d980799648
14 changed files with 2064 additions and 302 deletions
+76 -15
View File
@@ -54,12 +54,12 @@ pub struct Workspace {
}
impl Workspace {
fn begin_tab_rename(&mut self, window: &mut Window, cx: &mut Context<Self>) {
let Some(tab) = self.snapshot.as_ref().and_then(|snapshot| {
snapshot
.tabs
.iter()
.find(|tab| tab.id == snapshot.active_tab)
}) else {
let Some(tab) = self
.snapshot
.as_deref()
.and_then(Snapshot::active_tab)
.filter(|tab| !tab.is_connecting())
else {
return;
};
let id = tab.id;
@@ -166,6 +166,7 @@ impl Workspace {
if !matches!(
action,
CommandAction::TogglePalette
| CommandAction::NewWindow
| CommandAction::IncreaseFontSize
| CommandAction::DecreaseFontSize
) && (self.palette.is_some()
@@ -180,6 +181,30 @@ impl Workspace {
cx.stop_propagation();
}
fn open_window(&self, cx: &mut Context<Self>) {
let client = self.client.clone();
let cwd = self
.focused_pane()
.map(|pane| pane.read(cx).data().cwd.clone());
let active_tab = self.snapshot.as_deref().and_then(Snapshot::active_tab);
let remote = client
.remote()
.or_else(|| active_tab?.remote.as_deref())
.map(str::to_owned);
let launch = cx
.background_executor()
.spawn(async move { client.open_window(remote, cwd) });
cx.spawn(async move |view, cx| {
if let Err(error) = launch.await {
let _ = view.update(cx, |view, cx| {
view.error = Some(format!("Could not open a new window: {error:#}"));
cx.notify();
});
}
})
.detach();
}
fn execute(&mut self, action: CommandAction, window: &mut Window, cx: &mut Context<Self>) {
use CommandAction::*;
let pane = self.focused_pane();
@@ -189,6 +214,10 @@ impl Workspace {
self.open_palette(window, cx);
None
}
NewWindow => {
self.open_window(cx);
None
}
IncreaseFontSize | DecreaseFontSize => {
let delta = if matches!(action, IncreaseFontSize) {
1.
@@ -225,7 +254,13 @@ impl Workspace {
Direction::Down
},
}),
ClosePane => pane_id.map(|pane| ClientMessage::ClosePane { pane }),
ClosePane => pane_id
.map(|pane| ClientMessage::ClosePane { pane })
.or_else(|| {
let tab = self.snapshot.as_deref()?.active_tab()?;
tab.is_connecting()
.then_some(ClientMessage::ClosePendingTab { tab: tab.id })
}),
ResetPaneName => pane_id.map(|pane| ClientMessage::RenamePane { pane, name: None }),
ResetTabName => self
.snapshot
@@ -307,7 +342,8 @@ impl Workspace {
if cx
.update(|window, cx| {
view.update(cx, |view, cx| {
for text in update.clipboard {
for text in update.clipboard.into_iter().filter(|text| !text.is_empty())
{
cx.write_to_clipboard(ClipboardItem::new_string(text));
}
if let Some(error) = update.error {
@@ -535,12 +571,18 @@ impl Render for Workspace {
if let Some(snapshot) = &self.snapshot {
incoming = pane_scene(snapshot, &self.panes, incoming_offset, Some(&self.client));
if snapshot.panes.is_empty() {
incoming = incoming.child(
div()
.p_4()
.text_color(rgb(chrome::MUTED))
.child("No sessions. Use + to open a terminal."),
);
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));
}
}
} else {
incoming = incoming.child(
@@ -561,15 +603,34 @@ impl Render for Workspace {
.bg(rgb(chrome::APP_BACKGROUND))
.child(header)
.child(body);
#[cfg(target_os = "macos")]
{
root = root.on_action(cx.listener(|view, _: &crate::NewWindow, _, cx| {
view.open_window(cx);
}));
}
if let Some(error) = &self.error {
root = root.child(
div()
.flex()
.items_center()
.px_3()
.py_1()
.text_size(px(12.))
.text_color(rgb(chrome::TEXT))
.bg(rgb(chrome::BORDER))
.child(error.clone()),
.child(div().flex_1().min_w_0().child(error.clone()))
.child(
div()
.id("dismiss-error")
.px_2()
.cursor_pointer()
.child("Dismiss")
.on_click(cx.listener(|view, _, _, cx| {
view.error = None;
cx.notify();
})),
),
);
}
if let Some(palette) = &self.palette {