tmux: some plumbing for detaching and indicating tmux is active

the renderable interface is getting in the way though...

refs: https://github.com/wez/wezterm/issues/336
This commit is contained in:
Wez Furlong committed 2020-11-20 09:24:53 -08:00
1 parent aaf63285d2
commit fffb9b3fa0
2 files changed
+73 -2

No files matched your search

+24 -1
View File
@@ -21,6 +21,7 @@ pub struct LocalPane {
process: RefCell<Box<dyn Child>>,
pty: RefCell<Box<dyn MasterPty>>,
domain_id: DomainId,
tmux_domain: RefCell<Option<Arc<TmuxDomainState>>>,
}
#[async_trait(?Send)]
@@ -30,6 +31,15 @@ impl Pane for LocalPane {
}
fn renderer(&self) -> RefMut<dyn Renderable> {
/*
{
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::<LocalPane>().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::<LocalPane>().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),
}
}
+49 -1
View File
@@ -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<StableRowIndex>) -> RangeSet<StableRowIndex> {
let mut dirty = RangeSet::new();
for i in lines {
dirty.add(i);
}
dirty
}
fn get_lines(&mut self, lines: Range<StableRowIndex>) -> (StableRowIndex, Vec<Line>) {
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<tmux_cc::Parser>,
pub renderable: RefCell<TmuxPlaceholderRenderable>,
}
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 }
}