1
1
mirror of https://github.com/wez/wezterm.git synced 2024-11-26 16:34:23 +03:00

doc and cleanup

This commit is contained in:
g4c 2021-09-23 11:45:51 +08:00 committed by Wez Furlong
parent 6928415461
commit 8ee5c295f7
4 changed files with 19 additions and 12 deletions

View File

@ -5,7 +5,6 @@ use crate::tmux_commands::{ListAllPanes, TmuxCommand};
use crate::window::WindowId;
use crate::{Mux, MuxWindowBuilder};
use async_trait::async_trait;
use flume;
use portable_pty::{CommandBuilder, PtySize};
use std::cell::RefCell;
use std::collections::{HashMap, HashSet, VecDeque};
@ -40,6 +39,8 @@ pub(crate) struct TmuxRemotePane {
pub(crate) type RefTmuxRemotePane = Arc<Mutex<TmuxRemotePane>>;
/// As a remote TmuxTab, keeping the TmuxPanes ID
/// within the remote tab.
pub(crate) struct TmuxTab {
pub tab_id: TabId, // local tab ID
pub tmux_window_id: TmuxWindowId,
@ -48,9 +49,8 @@ pub(crate) struct TmuxTab {
pub(crate) type TmuxCmdQueue = VecDeque<Box<dyn TmuxCommand>>;
pub(crate) struct TmuxDomainState {
pub pane_id: PaneId,
pub domain_id: DomainId,
// parser: RefCell<Parser>,
pub pane_id: PaneId, // ID of the original pane
pub domain_id: DomainId, // ID of TmuxDomain
state: RefCell<State>,
pub cmd_queue: Arc<Mutex<TmuxCmdQueue>>,
pub gui_window: RefCell<Option<MuxWindowBuilder>>,
@ -124,10 +124,12 @@ impl TmuxDomainState {
// send pending commands to tmux
let cmd_queue = self.cmd_queue.as_ref().lock().unwrap();
if *self.state.borrow() == State::Idle && !cmd_queue.is_empty() {
TmuxDomainState::kick_off(self.domain_id);
TmuxDomainState::schedule_send_next_command(self.domain_id);
}
}
/// send next command at the front of cmd_queue.
/// must be called inside main thread
fn send_next_command(&self) {
if *self.state.borrow() != State::Idle {
return;
@ -145,7 +147,8 @@ impl TmuxDomainState {
}
}
pub fn kick_off(domain_id: usize) {
/// schedule a `send_next_command` into main thread
pub fn schedule_send_next_command(domain_id: usize) {
promise::spawn::spawn_into_main_thread(async move {
let mux = Mux::get().expect("to be called on main thread");
if let Some(domain) = mux.get_domain(domain_id) {
@ -157,6 +160,7 @@ impl TmuxDomainState {
.detach();
}
/// create a standalone window for tmux tabs
pub fn create_gui_window(&self) {
if self.gui_window.borrow().is_none() {
let mux = Mux::get().expect("should be call at main thread");

View File

@ -35,6 +35,7 @@ pub(crate) struct PaneItem {
}
impl TmuxDomainState {
/// check if a PaneItem received from ListAllPanes has been attached
fn check_pane_attached(&self, target: &PaneItem) -> bool {
let pane_list = self.gui_tabs.borrow();
let local_tab = match pane_list
@ -56,6 +57,8 @@ impl TmuxDomainState {
}
}
/// after we create a tab for a remote pane, save its ID into the
/// TmuxPane-TmuxPane tree, so we can ref it later.
fn add_attached_pane(&self, target: &PaneItem, tab_id: &TabId) -> anyhow::Result<()> {
let mut pane_list = self.gui_tabs.borrow_mut();
let local_tab = match pane_list
@ -295,7 +298,6 @@ impl TmuxCommand for SendKeys {
write!(&mut s, "0x{:X} ", byte).expect("unable to write key");
}
format!("send-keys -t {} {}\r", self.pane, s)
// FIXME: disable ESC k sequence
}
fn process_result(&self, _domain_id: DomainId, _result: &Guarded) -> anyhow::Result<()> {

View File

@ -2,7 +2,6 @@ use crate::{
tmux::{RefTmuxRemotePane, TmuxCmdQueue, TmuxDomainState},
tmux_commands::SendKeys,
};
use flume;
use portable_pty::{Child, ExitStatus, MasterPty};
use std::{
io::{Read, Write},
@ -26,13 +25,15 @@ impl Read for TmuxReader {
}
}
// A local tmux pane(tab) based on a tmux pty
/// A local tmux pane(tab) based on a tmux pty
#[derive(Debug, Clone)]
pub(crate) struct TmuxPty {
pub domain_id: usize,
pub master_pane: RefTmuxRemotePane,
pub rx: flume::Receiver<String>,
pub cmd_queue: Arc<Mutex<TmuxCmdQueue>>,
/// would be released by TmuxDomain when detatched
pub active_lock: Arc<(Mutex<bool>, Condvar)>,
}
@ -48,7 +49,7 @@ impl Write for TmuxPty {
pane: pane_id,
keys: buf.to_vec(),
}));
TmuxDomainState::kick_off(self.domain_id);
TmuxDomainState::schedule_send_next_command(self.domain_id);
Ok(0)
}

View File

@ -84,8 +84,8 @@ impl Parser {
}
pub fn parse<F: FnMut(Action)>(&mut self, bytes: &[u8], mut callback: F) {
let tmux_state: bool = self.state.borrow().tmux_state.is_some();
if tmux_state {
let is_tmux_mode: bool = self.state.borrow().tmux_state.is_some();
if is_tmux_mode {
if let Some(unparsed_str) = {
let parser_state = self.state.borrow();
let tmux_state = parser_state.tmux_state.as_ref().unwrap();