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:
+63
-3
@@ -10,10 +10,37 @@ use anyhow::{Context, Result, bail};
|
||||
use bincode::Options;
|
||||
use serde::{Deserialize, Serialize, de::DeserializeOwned};
|
||||
|
||||
pub const VERSION: u32 = 4;
|
||||
pub const VERSION: u32 = 6;
|
||||
pub const MAX_MESSAGE_BYTES: usize = 16 * 1024 * 1024;
|
||||
pub type PaneId = u64;
|
||||
pub type TabId = u64;
|
||||
pub type SessionId = u64;
|
||||
|
||||
#[derive(Debug, Clone, Copy, Hash, Eq, PartialEq, Ord, PartialOrd, Serialize, Deserialize)]
|
||||
pub struct SessionIdentity {
|
||||
pub server: [u8; 16],
|
||||
pub session: SessionId,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub enum SessionTarget {
|
||||
New { cwd: Option<String> },
|
||||
Attach(Option<SessionId>),
|
||||
}
|
||||
|
||||
/// SSH settings inherited from the shell that requested a remote tab.
|
||||
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
|
||||
pub struct SshOptions {
|
||||
pub executable: Option<String>,
|
||||
pub agent_socket: Option<std::path::PathBuf>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct SessionInfo {
|
||||
pub id: SessionId,
|
||||
pub attached: usize,
|
||||
pub tabs: Vec<TabInfo>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
// Keep variants append-only: the shutdown command can retire an older server.
|
||||
@@ -21,7 +48,7 @@ pub enum ClientMessage {
|
||||
Hello {
|
||||
version: u32,
|
||||
},
|
||||
Attach,
|
||||
Connect(SessionTarget),
|
||||
Input {
|
||||
pane: PaneId,
|
||||
bytes: Vec<u8>,
|
||||
@@ -62,11 +89,12 @@ pub enum ClientMessage {
|
||||
},
|
||||
OpenWindow {
|
||||
target: Option<String>,
|
||||
session: SessionTarget,
|
||||
},
|
||||
Detach,
|
||||
Shutdown,
|
||||
Ping,
|
||||
/// Read current layout without attaching or creating a shell.
|
||||
/// Inspect the layout of the session this client has joined.
|
||||
List,
|
||||
/// A blank/absent name returns to program-title/CWD naming.
|
||||
RenamePane {
|
||||
@@ -101,6 +129,17 @@ pub enum ClientMessage {
|
||||
tab: TabId,
|
||||
name: Option<String>,
|
||||
},
|
||||
ListSessions,
|
||||
OpenRemoteTab {
|
||||
session: SessionIdentity,
|
||||
pane: PaneId,
|
||||
destination: String,
|
||||
target: SessionTarget,
|
||||
ssh: SshOptions,
|
||||
},
|
||||
ClosePendingTab {
|
||||
tab: TabId,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
||||
@@ -164,10 +203,14 @@ pub enum ServerMessage {
|
||||
Error(String),
|
||||
Pong,
|
||||
Closing,
|
||||
Connected { session: SessionId },
|
||||
Sessions(Vec<SessionInfo>),
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct Snapshot {
|
||||
/// This session and the other sessions contributing tabs to its layout.
|
||||
pub lineage: Vec<SessionIdentity>,
|
||||
pub revision: u64,
|
||||
pub tabs: Vec<TabInfo>,
|
||||
pub active_tab: TabId,
|
||||
@@ -175,9 +218,17 @@ pub struct Snapshot {
|
||||
pub panes: Vec<PaneSnapshot>,
|
||||
}
|
||||
|
||||
impl Snapshot {
|
||||
pub fn active_tab(&self) -> Option<&TabInfo> {
|
||||
self.tabs.iter().find(|tab| tab.id == self.active_tab)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct TabInfo {
|
||||
pub id: TabId,
|
||||
/// SSH destination for a tab mounted from another host.
|
||||
pub remote: Option<String>,
|
||||
/// Effective display name: manual override, then the selected pane's name.
|
||||
pub title: String,
|
||||
pub manual_title: Option<String>,
|
||||
@@ -188,6 +239,15 @@ pub struct TabInfo {
|
||||
pub stacks: Vec<StackInfo>,
|
||||
}
|
||||
|
||||
impl TabInfo {
|
||||
pub fn is_connecting(&self) -> bool {
|
||||
self.remote.is_some()
|
||||
&& self.panes.is_empty()
|
||||
&& self.stacks.is_empty()
|
||||
&& self.active_pane == 0
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct StackInfo {
|
||||
pub panes: Vec<StackPaneInfo>,
|
||||
|
||||
Reference in New Issue
Block a user