diff --git a/mux/src/localpane.rs b/mux/src/localpane.rs index 82174aeec..dea56e56d 100644 --- a/mux/src/localpane.rs +++ b/mux/src/localpane.rs @@ -21,6 +21,7 @@ pub struct LocalPane { process: RefCell>, pty: RefCell>, domain_id: DomainId, + tmux_domain: RefCell>>, } #[async_trait(?Send)] @@ -30,6 +31,15 @@ impl Pane for LocalPane { } fn renderer(&self) -> RefMut { + /* + { + let tmux_domain = self.tmux_domain.borrow(); + let mut tmux = tmux_domain.as_ref().cloned(); + if let Some(tmux) = tmux.take() { + return RefMut::map(tmux.renderable.borrow_mut(), |r| &mut *r); + } + } + */ RefMut::map(self.terminal.borrow_mut(), |t| &mut *t) } @@ -254,6 +264,13 @@ impl wezterm_term::DeviceControlHandler for LocalPaneDCSHandler { let mux = Mux::get().expect("to be called on main thread"); mux.add_domain(&domain); + if let Some(pane) = mux.get_pane(self.pane_id) { + let pane = pane.downcast_ref::().unwrap(); + pane.tmux_domain + .borrow_mut() + .replace(Arc::clone(&tmux_domain)); + } + self.tmux_domain.replace(tmux_domain); // TODO: do we need to proactively list available tabs here? @@ -265,7 +282,12 @@ impl wezterm_term::DeviceControlHandler for LocalPaneDCSHandler { } DeviceControlMode::Exit => { if let Some(tmux) = self.tmux_domain.take() { - log::error!("FIXME: detach domain here!"); + let mux = Mux::get().expect("to be called on main thread"); + if let Some(pane) = mux.get_pane(self.pane_id) { + let pane = pane.downcast_ref::().unwrap(); + pane.tmux_domain.borrow_mut().take(); + } + mux.domain_was_detached(tmux.domain_id); } } DeviceControlMode::Data(c) => { @@ -304,6 +326,7 @@ impl LocalPane { process: RefCell::new(process), pty: RefCell::new(pty), domain_id, + tmux_domain: RefCell::new(None), } } diff --git a/mux/src/tmux.rs b/mux/src/tmux.rs index e6002912a..be2aadb8d 100644 --- a/mux/src/tmux.rs +++ b/mux/src/tmux.rs @@ -1,17 +1,63 @@ use crate::domain::{alloc_domain_id, Domain, DomainId, DomainState}; use crate::pane::{Pane, PaneId}; +use crate::renderable::*; use crate::tab::{SplitDirection, Tab, TabId}; use crate::window::WindowId; use async_trait::async_trait; use portable_pty::{CommandBuilder, PtySize}; +use rangeset::RangeSet; use std::cell::RefCell; +use std::ops::Range; use std::rc::Rc; use std::sync::Arc; +use termwiz::surface::Line; +use wezterm_term::{CellAttributes, StableRowIndex}; + +pub(crate) struct TmuxPlaceholderRenderable {} + +impl Renderable for TmuxPlaceholderRenderable { + fn get_cursor_position(&self) -> StableCursorPosition { + StableCursorPosition { + x: 0, + y: 0, + shape: Default::default(), + visibility: termwiz::surface::CursorVisibility::Hidden, + } + } + + fn get_dirty_lines(&self, lines: Range) -> RangeSet { + let mut dirty = RangeSet::new(); + for i in lines { + dirty.add(i); + } + dirty + } + + fn get_lines(&mut self, lines: Range) -> (StableRowIndex, Vec) { + let line = Line::from_text( + "This pane is running tmux control mode", + &CellAttributes::default(), + ); + (0, vec![line]) + } + + /// Returns render related dimensions + fn get_dimensions(&self) -> RenderableDimensions { + RenderableDimensions { + cols: 32, + viewport_rows: 1, + scrollback_rows: 0, + physical_top: 0, + scrollback_top: 0, + } + } +} pub(crate) struct TmuxDomainState { pane_id: PaneId, - domain_id: DomainId, + pub domain_id: DomainId, parser: RefCell, + pub renderable: RefCell, } pub struct TmuxDomain { @@ -31,10 +77,12 @@ impl TmuxDomain { pub fn new(pane_id: PaneId) -> Self { let domain_id = alloc_domain_id(); let parser = RefCell::new(tmux_cc::Parser::new()); + let renderable = RefCell::new(TmuxPlaceholderRenderable {}); let inner = Arc::new(TmuxDomainState { domain_id, pane_id, parser, + renderable, }); Self { inner } }