From 23c777aaddf355f4a9b9b52d081fb0ff302897bf Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Sun, 27 Sep 2020 20:04:41 -0700 Subject: [PATCH] wezterm: export WEZTERM_PANE= When spawning processes, export the local pane_id. refs: https://github.com/wez/wezterm/issues/230 --- src/localtab.rs | 4 ++-- src/mux/domain.rs | 23 ++++++++++++++++++++--- src/ssh.rs | 14 +++++++++++--- 3 files changed, 33 insertions(+), 8 deletions(-) diff --git a/src/localtab.rs b/src/localtab.rs index 91b15aa17..8b6a26237 100644 --- a/src/localtab.rs +++ b/src/localtab.rs @@ -1,6 +1,6 @@ use crate::mux::domain::DomainId; use crate::mux::renderable::Renderable; -use crate::mux::tab::{alloc_pane_id, Pane, PaneId}; +use crate::mux::tab::{Pane, PaneId}; use crate::mux::tab::{Pattern, SearchResult}; use anyhow::Error; use async_trait::async_trait; @@ -223,12 +223,12 @@ impl Pane for LocalPane { impl LocalPane { pub fn new( + pane_id: PaneId, terminal: Terminal, process: Box, pty: Box, domain_id: DomainId, ) -> Self { - let pane_id = alloc_pane_id(); Self { pane_id, terminal: RefCell::new(terminal), diff --git a/src/mux/domain.rs b/src/mux/domain.rs index 34fb07149..4afc800c3 100644 --- a/src/mux/domain.rs +++ b/src/mux/domain.rs @@ -7,7 +7,7 @@ use crate::config::configuration; use crate::localtab::LocalPane; -use crate::mux::tab::{Pane, PaneId, SplitDirection, Tab, TabId}; +use crate::mux::tab::{alloc_pane_id, Pane, PaneId, SplitDirection, Tab, TabId}; use crate::mux::window::WindowId; use crate::mux::Mux; use anyhow::{bail, Error}; @@ -130,6 +130,9 @@ impl Domain for LocalDomain { } } let pair = self.pty_system.openpty(size)?; + let pane_id = alloc_pane_id(); + cmd.env("WEZTERM_PANE", pane_id.to_string()); + let child = pair.slave.spawn_command(cmd)?; info!("spawned: {:?}", child); @@ -147,7 +150,13 @@ impl Domain for LocalDomain { ); let mux = Mux::get().unwrap(); - let pane: Rc = Rc::new(LocalPane::new(terminal, child, pair.master, self.id)); + let pane: Rc = Rc::new(LocalPane::new( + pane_id, + terminal, + child, + pair.master, + self.id, + )); let tab = Rc::new(Tab::new(&size)); tab.assign_pane(&pane); @@ -204,6 +213,8 @@ impl Domain for LocalDomain { } } let pair = self.pty_system.openpty(split_size.second)?; + let pane_id = alloc_pane_id(); + cmd.env("WEZTERM_PANE", pane_id.to_string()); let child = pair.slave.spawn_command(cmd)?; info!("spawned: {:?}", child); @@ -220,7 +231,13 @@ impl Domain for LocalDomain { Box::new(writer), ); - let pane: Rc = Rc::new(LocalPane::new(terminal, child, pair.master, self.id)); + let pane: Rc = Rc::new(LocalPane::new( + pane_id, + terminal, + child, + pair.master, + self.id, + )); tab.split_and_insert(pane_index, direction, Rc::clone(&pane))?; diff --git a/src/ssh.rs b/src/ssh.rs index da1e2b6fe..50048523a 100644 --- a/src/ssh.rs +++ b/src/ssh.rs @@ -1,7 +1,7 @@ use crate::connui::ConnectionUI; use crate::localtab::LocalPane; use crate::mux::domain::{alloc_domain_id, Domain, DomainId, DomainState}; -use crate::mux::tab::{Pane, PaneId, SplitDirection, Tab, TabId}; +use crate::mux::tab::{alloc_pane_id, Pane, PaneId, SplitDirection, Tab, TabId}; use crate::mux::window::WindowId; use crate::mux::Mux; use anyhow::{anyhow, bail, Context, Error}; @@ -242,11 +242,13 @@ impl Domain for RemoteSshDomain { _command_dir: Option, window: WindowId, ) -> Result, Error> { - let cmd = match command { + let mut cmd = match command { Some(c) => c, None => CommandBuilder::new_default_prog(), }; let pair = self.pty_system.openpty(size)?; + let pane_id = alloc_pane_id(); + cmd.env("WEZTERM_PANE", pane_id.to_string()); let child = pair.slave.spawn_command(cmd)?; log::info!("spawned: {:?}", child); @@ -264,7 +266,13 @@ impl Domain for RemoteSshDomain { ); let mux = Mux::get().unwrap(); - let pane: Rc = Rc::new(LocalPane::new(terminal, child, pair.master, self.id)); + let pane: Rc = Rc::new(LocalPane::new( + pane_id, + terminal, + child, + pair.master, + self.id, + )); let tab = Rc::new(Tab::new(&size)); tab.assign_pane(&pane);