diff --git a/codec/src/lib.rs b/codec/src/lib.rs index fd45f0788..d83383d4a 100644 --- a/codec/src/lib.rs +++ b/codec/src/lib.rs @@ -434,6 +434,7 @@ pdu! { SearchScrollbackResponse: 32, SetPaneZoomed: 33, SplitPane: 34, + KillPane: 35, } impl Pdu { @@ -577,6 +578,11 @@ pub struct SplitPane { pub domain: config::keyassignment::SpawnTabDomain, } +#[derive(Deserialize, Serialize, PartialEq, Debug)] +pub struct KillPane { + pub pane_id: PaneId, +} + #[derive(Deserialize, Serialize, PartialEq, Debug)] pub struct SpawnResponse { pub tab_id: TabId, diff --git a/wezterm-client/src/client.rs b/wezterm-client/src/client.rs index 0e380217a..342140d41 100644 --- a/wezterm-client/src/client.rs +++ b/wezterm-client/src/client.rs @@ -952,4 +952,5 @@ impl Client { SearchScrollbackRequest, SearchScrollbackResponse ); + rpc!(kill_pane, KillPane, UnitResponse); } diff --git a/wezterm-client/src/pane/clienttab.rs b/wezterm-client/src/pane/clienttab.rs index a6558be42..3b6c70daa 100644 --- a/wezterm-client/src/pane/clienttab.rs +++ b/wezterm-client/src/pane/clienttab.rs @@ -294,6 +294,20 @@ impl Pane for ClientPane { Ok(()) } + fn kill(&self) { + let client = Arc::clone(&self.client); + let remote_pane_id = self.remote_pane_id; + promise::spawn::spawn(async move { + client + .client + .kill_pane(KillPane { + pane_id: remote_pane_id, + }) + .await + }) + .detach(); + } + fn mouse_event(&self, event: MouseEvent) -> anyhow::Result<()> { self.mouse.borrow_mut().append(event); if MouseState::next(Rc::clone(&self.mouse)) { diff --git a/wezterm-mux-server-impl/src/sessionhandler.rs b/wezterm-mux-server-impl/src/sessionhandler.rs index fce4011ae..05bc8fcee 100644 --- a/wezterm-mux-server-impl/src/sessionhandler.rs +++ b/wezterm-mux-server-impl/src/sessionhandler.rs @@ -250,6 +250,26 @@ impl SessionHandler { }) .detach(); } + Pdu::KillPane(KillPane { pane_id }) => { + let sender = self.to_write_tx.clone(); + let per_pane = self.per_pane(pane_id); + spawn_into_main_thread(async move { + catch( + move || { + let mux = Mux::get().unwrap(); + let pane = mux + .get_pane(pane_id) + .ok_or_else(|| anyhow!("no such pane {}", pane_id))?; + pane.kill(); + mux.remove_pane(pane_id); + maybe_push_pane_changes(&pane, sender, per_pane)?; + Ok(Pdu::UnitResponse(UnitResponse {})) + }, + send_response, + ); + }) + .detach(); + } Pdu::SendPaste(SendPaste { pane_id, data }) => { let sender = self.to_write_tx.clone(); let per_pane = self.per_pane(pane_id);