mux: split-pane can optionally move an existing pane into the split
This commit allows for the SplitPane internal action to use the pane id of an existing pane as the source of the pane to be added in the new split target, rather than spawning a new command. This can be used to move a pane from one tab to another, and is analagous to tmux's `join-pane` command. refs: https://github.com/wez/wezterm/discussions/2043 refs: https://github.com/wez/wezterm/issues/1253
This commit is contained in:
1 parent
8d29631808
commit
c4a248f1a3
8 files changed
+116
-36
No files matched your search
+4
-1
@@ -416,7 +416,7 @@ macro_rules! pdu {
|
||||
/// The overall version of the codec.
|
||||
/// This must be bumped when backwards incompatible changes
|
||||
/// are made to the types and protocol.
|
||||
pub const CODEC_VERSION: usize = 23;
|
||||
pub const CODEC_VERSION: usize = 24;
|
||||
|
||||
// Defines the Pdu enum.
|
||||
// Each struct has an explicit identifying number.
|
||||
@@ -596,6 +596,9 @@ pub struct SplitPane {
|
||||
pub command: Option<CommandBuilder>,
|
||||
pub command_dir: Option<String>,
|
||||
pub domain: config::keyassignment::SpawnTabDomain,
|
||||
/// Instead of spawning a command, move the specified
|
||||
/// pane into the new split target
|
||||
pub move_pane_id: Option<PaneId>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Serialize, PartialEq, Debug)]
|
||||
|
||||
+38
-5
@@ -31,6 +31,15 @@ pub fn alloc_domain_id() -> DomainId {
|
||||
DOMAIN_ID.fetch_add(1, ::std::sync::atomic::Ordering::Relaxed)
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub enum SplitSource {
|
||||
Spawn {
|
||||
command: Option<CommandBuilder>,
|
||||
command_dir: Option<String>,
|
||||
},
|
||||
MovePane(PaneId),
|
||||
}
|
||||
|
||||
#[async_trait(?Send)]
|
||||
pub trait Domain: Downcast {
|
||||
/// Spawn a new command within this domain
|
||||
@@ -55,8 +64,7 @@ pub trait Domain: Downcast {
|
||||
|
||||
async fn split_pane(
|
||||
&self,
|
||||
command: Option<CommandBuilder>,
|
||||
command_dir: Option<String>,
|
||||
source: SplitSource,
|
||||
tab: TabId,
|
||||
pane_id: PaneId,
|
||||
split_request: SplitRequest,
|
||||
@@ -81,9 +89,34 @@ pub trait Domain: Downcast {
|
||||
None => anyhow::bail!("invalid pane index {}", pane_index),
|
||||
};
|
||||
|
||||
let pane = self
|
||||
.spawn_pane(split_size.second, command, command_dir)
|
||||
.await?;
|
||||
let pane = match source {
|
||||
SplitSource::Spawn {
|
||||
command,
|
||||
command_dir,
|
||||
} => {
|
||||
self.spawn_pane(split_size.second, command, command_dir)
|
||||
.await?
|
||||
}
|
||||
SplitSource::MovePane(src_pane_id) => {
|
||||
let (_domain, _window, src_tab) = mux
|
||||
.resolve_pane_id(src_pane_id)
|
||||
.ok_or_else(|| anyhow::anyhow!("pane {} not found", src_pane_id))?;
|
||||
let src_tab = match mux.get_tab(src_tab) {
|
||||
Some(t) => t,
|
||||
None => anyhow::bail!("Invalid tab id {}", src_tab),
|
||||
};
|
||||
|
||||
let pane = src_tab.remove_pane(src_pane_id).ok_or_else(|| {
|
||||
anyhow::anyhow!("pane {} not found in its containing tab!?", src_pane_id)
|
||||
})?;
|
||||
|
||||
if src_tab.is_dead() {
|
||||
mux.remove_tab(src_tab.tab_id());
|
||||
}
|
||||
|
||||
pane
|
||||
}
|
||||
};
|
||||
|
||||
tab.split_and_insert(pane_index, split_request, Rc::clone(&pane))?;
|
||||
Ok(pane)
|
||||
|
||||
+13
-7
@@ -5,7 +5,7 @@ use crate::window::{Window, WindowId};
|
||||
use anyhow::{anyhow, Context, Error};
|
||||
use config::keyassignment::SpawnTabDomain;
|
||||
use config::{configuration, ExitBehavior};
|
||||
use domain::{Domain, DomainId, DomainState};
|
||||
use domain::{Domain, DomainId, DomainState, SplitSource};
|
||||
use filedescriptor::{socketpair, AsRawSocketDescriptor, FileDescriptor};
|
||||
#[cfg(unix)]
|
||||
use libc::{SOL_SOCKET, SO_RCVBUF, SO_SNDBUF};
|
||||
@@ -942,8 +942,7 @@ impl Mux {
|
||||
// TODO: disambiguate with TabId
|
||||
pane_id: PaneId,
|
||||
request: SplitRequest,
|
||||
command: Option<CommandBuilder>,
|
||||
command_dir: Option<String>,
|
||||
source: SplitSource,
|
||||
domain: config::keyassignment::SpawnTabDomain,
|
||||
) -> anyhow::Result<(Rc<dyn Pane>, PtySize)> {
|
||||
let (_pane_domain_id, window_id, tab_id) = self
|
||||
@@ -963,11 +962,18 @@ impl Mux {
|
||||
.ok_or_else(|| anyhow!("pane_id {} is invalid", pane_id))?;
|
||||
let term_config = current_pane.get_config();
|
||||
|
||||
let cwd = self.resolve_cwd(command_dir, Some(Rc::clone(¤t_pane)));
|
||||
let source = match source {
|
||||
SplitSource::Spawn {
|
||||
command,
|
||||
command_dir,
|
||||
} => SplitSource::Spawn {
|
||||
command,
|
||||
command_dir: self.resolve_cwd(command_dir, Some(Rc::clone(¤t_pane))),
|
||||
},
|
||||
other => other,
|
||||
};
|
||||
|
||||
let pane = domain
|
||||
.split_pane(command, cwd, tab_id, pane_id, request)
|
||||
.await?;
|
||||
let pane = domain.split_pane(source, tab_id, pane_id, request).await?;
|
||||
if let Some(config) = term_config {
|
||||
pane.set_config(config);
|
||||
}
|
||||
|
||||
+27
-11
@@ -1264,18 +1264,35 @@ impl Tab {
|
||||
}
|
||||
|
||||
pub fn prune_dead_panes(&self) -> bool {
|
||||
self.remove_pane_if(|_, pane| pane.is_dead())
|
||||
!self
|
||||
.remove_pane_if(|_, pane| pane.is_dead(), true)
|
||||
.is_empty()
|
||||
}
|
||||
|
||||
pub fn kill_pane(&self, pane_id: PaneId) -> bool {
|
||||
self.remove_pane_if(|_, pane| pane.pane_id() == pane_id)
|
||||
!self
|
||||
.remove_pane_if(|_, pane| pane.pane_id() == pane_id, true)
|
||||
.is_empty()
|
||||
}
|
||||
|
||||
pub fn kill_panes_in_domain(&self, domain: DomainId) -> bool {
|
||||
self.remove_pane_if(|_, pane| pane.domain_id() == domain)
|
||||
!self
|
||||
.remove_pane_if(|_, pane| pane.domain_id() == domain, true)
|
||||
.is_empty()
|
||||
}
|
||||
|
||||
fn remove_pane_if<F>(&self, f: F) -> bool
|
||||
/// Remove pane from tab.
|
||||
/// The pane is still live in the mux; the intent is for the pane to
|
||||
/// be added to a different tab.
|
||||
pub fn remove_pane(&self, pane_id: PaneId) -> Option<Rc<dyn Pane>> {
|
||||
let panes = self.remove_pane_if(|_, pane| pane.pane_id() == pane_id, false);
|
||||
for pane in panes {
|
||||
return Some(pane);
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
fn remove_pane_if<F>(&self, f: F, kill: bool) -> Vec<Rc<dyn Pane>>
|
||||
where
|
||||
F: Fn(usize, &Rc<dyn Pane>) -> bool,
|
||||
{
|
||||
@@ -1316,7 +1333,7 @@ impl Tab {
|
||||
let parent;
|
||||
match cursor.unsplit_leaf() {
|
||||
Ok((c, dead, p)) => {
|
||||
dead_panes.push(dead.pane_id());
|
||||
dead_panes.push(dead);
|
||||
parent = p.unwrap();
|
||||
cursor = c;
|
||||
}
|
||||
@@ -1324,7 +1341,7 @@ impl Tab {
|
||||
// We might be the root, for example
|
||||
if c.is_top() && c.is_leaf() {
|
||||
root.replace(Tree::Empty);
|
||||
dead_panes.push(pane.pane_id());
|
||||
dead_panes.push(pane);
|
||||
} else {
|
||||
root.replace(c.tree());
|
||||
}
|
||||
@@ -1366,18 +1383,17 @@ impl Tab {
|
||||
*self.active.borrow_mut() = active_idx;
|
||||
}
|
||||
|
||||
if !dead_panes.is_empty() {
|
||||
if !dead_panes.is_empty() && kill {
|
||||
let to_kill: Vec<_> = dead_panes.iter().map(|p| p.pane_id()).collect();
|
||||
promise::spawn::spawn_into_main_thread(async move {
|
||||
let mux = Mux::get().unwrap();
|
||||
for pane_id in dead_panes.into_iter() {
|
||||
for pane_id in to_kill.into_iter() {
|
||||
mux.remove_pane(pane_id);
|
||||
}
|
||||
})
|
||||
.detach();
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
dead_panes
|
||||
}
|
||||
|
||||
pub fn can_close_without_prompting(&self, reason: CloseReason) -> bool {
|
||||
|
||||
@@ -6,7 +6,7 @@ use codec::{ListPanesResponse, SpawnV2, SplitPane};
|
||||
use config::keyassignment::SpawnTabDomain;
|
||||
use config::{SshDomain, TlsDomainClient, UnixDomain};
|
||||
use mux::connui::{ConnectionUI, ConnectionUIParams};
|
||||
use mux::domain::{alloc_domain_id, Domain, DomainId, DomainState};
|
||||
use mux::domain::{alloc_domain_id, Domain, DomainId, DomainState, SplitSource};
|
||||
use mux::pane::{Pane, PaneId};
|
||||
use mux::tab::{SplitRequest, Tab, TabId};
|
||||
use mux::window::WindowId;
|
||||
@@ -537,8 +537,7 @@ impl Domain for ClientDomain {
|
||||
|
||||
async fn split_pane(
|
||||
&self,
|
||||
command: Option<CommandBuilder>,
|
||||
command_dir: Option<String>,
|
||||
source: SplitSource,
|
||||
tab_id: TabId,
|
||||
pane_id: PaneId,
|
||||
split_request: SplitRequest,
|
||||
@@ -559,6 +558,14 @@ impl Domain for ClientDomain {
|
||||
.downcast_ref::<ClientPane>()
|
||||
.ok_or_else(|| anyhow!("pane_id {} is not a ClientPane", pane_id))?;
|
||||
|
||||
let (command, command_dir, move_pane_id) = match source {
|
||||
SplitSource::Spawn {
|
||||
command,
|
||||
command_dir,
|
||||
} => (command, command_dir, None),
|
||||
SplitSource::MovePane(move_pane_id) => (None, None, Some(move_pane_id)),
|
||||
};
|
||||
|
||||
let result = inner
|
||||
.client
|
||||
.split_pane(SplitPane {
|
||||
@@ -567,6 +574,7 @@ impl Domain for ClientDomain {
|
||||
split_request,
|
||||
command,
|
||||
command_dir,
|
||||
move_pane_id,
|
||||
})
|
||||
.await?;
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ use anyhow::{anyhow, bail, Context};
|
||||
use config::keyassignment::{SpawnCommand, SpawnTabDomain};
|
||||
use config::TermConfig;
|
||||
use mux::activity::Activity;
|
||||
use mux::domain::SplitSource;
|
||||
use mux::tab::SplitRequest;
|
||||
use mux::Mux;
|
||||
use portable_pty::{CommandBuilder, PtySize};
|
||||
@@ -102,8 +103,10 @@ impl super::TermWindow {
|
||||
// tab.tab_id(),
|
||||
pane.pane_id(),
|
||||
direction,
|
||||
cmd_builder,
|
||||
cwd,
|
||||
SplitSource::Spawn {
|
||||
command: cmd_builder,
|
||||
command_dir: cwd,
|
||||
},
|
||||
spawn.domain,
|
||||
)
|
||||
.await
|
||||
|
||||
@@ -2,6 +2,7 @@ use crate::PKI;
|
||||
use anyhow::{anyhow, Context};
|
||||
use codec::*;
|
||||
use mux::client::ClientId;
|
||||
use mux::domain::SplitSource;
|
||||
use mux::pane::{Pane, PaneId};
|
||||
use mux::renderable::{RenderableDimensions, StableCursorPosition};
|
||||
use mux::tab::TabId;
|
||||
@@ -719,14 +720,17 @@ async fn split_pane(split: SplitPane, client_id: Option<Arc<ClientId>>) -> anyho
|
||||
.resolve_pane_id(split.pane_id)
|
||||
.ok_or_else(|| anyhow!("pane_id {} invalid", split.pane_id))?;
|
||||
|
||||
let source = if let Some(move_pane_id) = split.move_pane_id {
|
||||
SplitSource::MovePane(move_pane_id)
|
||||
} else {
|
||||
SplitSource::Spawn {
|
||||
command: split.command,
|
||||
command_dir: split.command_dir,
|
||||
}
|
||||
};
|
||||
|
||||
let (pane, size) = mux
|
||||
.split_pane(
|
||||
split.pane_id,
|
||||
split.split_request,
|
||||
split.command,
|
||||
split.command_dir,
|
||||
split.domain,
|
||||
)
|
||||
.split_pane(split.pane_id, split.split_request, source, split.domain)
|
||||
.await?;
|
||||
|
||||
Ok::<Pdu, anyhow::Error>(Pdu::SpawnResponse(SpawnResponse {
|
||||
|
||||
@@ -212,6 +212,11 @@ Outputs the pane-id for the newly created pane on success"
|
||||
#[structopt(long, parse(from_os_str))]
|
||||
cwd: Option<OsString>,
|
||||
|
||||
/// Instead of spawning a new command, move the specified
|
||||
/// pane into the newly created split.
|
||||
#[structopt(long, conflicts_with_all=&["cwd", "prog"])]
|
||||
move_pane_id: Option<PaneId>,
|
||||
|
||||
/// Instead of executing your shell, run PROG.
|
||||
/// For example: `wezterm cli split-pane -- bash -l` will spawn bash
|
||||
/// as if it were a login shell.
|
||||
@@ -787,6 +792,7 @@ async fn run_cli_async(config: config::ConfigHandle, cli: CliCommand) -> anyhow:
|
||||
top_level,
|
||||
cells,
|
||||
percent,
|
||||
move_pane_id,
|
||||
} => {
|
||||
let pane_id = resolve_pane_id(&client, pane_id).await?;
|
||||
|
||||
@@ -823,6 +829,7 @@ async fn run_cli_async(config: config::ConfigHandle, cli: CliCommand) -> anyhow:
|
||||
Some(builder)
|
||||
},
|
||||
command_dir: canon_cwd(cwd)?,
|
||||
move_pane_id,
|
||||
})
|
||||
.await?;
|
||||
|
||||
|
||||
Reference in new issue
Block a user