diff --git a/mux/src/tmux.rs b/mux/src/tmux.rs index 0fcfd2133..417237e97 100644 --- a/mux/src/tmux.rs +++ b/mux/src/tmux.rs @@ -1,7 +1,7 @@ use crate::domain::{alloc_domain_id, Domain, DomainId, DomainState}; use crate::pane::{Pane, PaneId}; use crate::tab::{SplitDirection, Tab, TabId}; -use crate::tmux_commands::{ListAllPanes, TmuxCommand}; +use crate::tmux_commands::{process_command_result, ListAllPanes, TmuxCommand}; use crate::window::WindowId; use crate::Mux; use async_trait::async_trait; @@ -62,8 +62,11 @@ impl TmuxDomainState { *self.state.borrow_mut() = State::Idle; let resp = response.clone(); promise::spawn::spawn(async move { - if let Err(err) = cmd.process_result(domain_id, &resp) { - log::error!("error processing result: {}", err); + match cmd.process_result(domain_id, &resp) { + Ok(result) => process_command_result(domain_id, result), + Err(err) => { + log::error!("error processing result: {}", err); + } } }) .detach(); diff --git a/mux/src/tmux_commands.rs b/mux/src/tmux_commands.rs index 1014090e2..42195aa99 100644 --- a/mux/src/tmux_commands.rs +++ b/mux/src/tmux_commands.rs @@ -1,8 +1,34 @@ +use crate::domain::DomainId; +use crate::tmux::TmuxDomain; +use crate::Mux; use anyhow::anyhow; +use tmux_cc::*; pub(crate) trait TmuxCommand { fn get_command(&self) -> String; - fn process_result(&self, domain_id: DomainId, result: &Guarded) -> anyhow::Result<()>; + fn process_result( + &self, + domain_id: DomainId, + result: &Guarded, + ) -> anyhow::Result; +} + +#[derive(Debug)] +pub(crate) struct PaneItem { + session_id: TmuxSessionId, + window_id: TmuxWindowId, + pane_id: TmuxPaneId, + pane_index: u64, + cursor_x: u64, + cursor_y: u64, + pane_width: u64, + pane_height: u64, + pane_left: u64, + pane_top: u64, +} + +pub(crate) enum TmuxCommandResult { + PaneList(Vec), } pub(crate) struct ListAllPanes; @@ -14,21 +40,11 @@ impl TmuxCommand for ListAllPanes { .to_owned() } - fn process_result(&self, domain_id: DomainId, result: &Guarded) -> anyhow::Result<()> { - #[derive(Debug)] - struct Item { - session_id: TmuxSessionId, - window_id: TmuxWindowId, - pane_id: TmuxPaneId, - pane_index: u64, - cursor_x: u64, - cursor_y: u64, - pane_width: u64, - pane_height: u64, - pane_left: u64, - pane_top: u64, - } - + fn process_result( + &self, + domain_id: DomainId, + result: &Guarded, + ) -> anyhow::Result { let mut items = vec![]; for line in result.output.split('\n') { @@ -74,7 +90,7 @@ impl TmuxCommand for ListAllPanes { let window_id = window_id[1..].parse()?; let pane_id = pane_id[1..].parse()?; - items.push(Item { + items.push(PaneItem { session_id, window_id, pane_id, @@ -89,6 +105,15 @@ impl TmuxCommand for ListAllPanes { } log::error!("panes in domain_id {}: {:?}", domain_id, items); - Ok(()) + Ok(TmuxCommandResult::PaneList(items)) + } +} + +pub(crate) fn process_command_result(domain_id: DomainId, result: TmuxCommandResult) { + let mux = Mux::get().expect("to be called on main thread"); + if let Some(domain) = mux.get_domain(domain_id) { + if let Some(tmux_domain) = domain.downcast_ref::() { + // TODO: + } } } diff --git a/termwiz/src/escape/parser/mod.rs b/termwiz/src/escape/parser/mod.rs index 471d0a9ef..8ffa4dfcf 100644 --- a/termwiz/src/escape/parser/mod.rs +++ b/termwiz/src/escape/parser/mod.rs @@ -89,6 +89,7 @@ impl Parser { let parser_state = self.state.borrow(); let tmux_state = parser_state.tmux_state.as_ref().unwrap(); let mut tmux_parser = tmux_state.borrow_mut(); + // TODO: wrap events into some Result to capture bytes cannot be parsed let tmux_events = tmux_parser.advance_bytes(bytes); log::info!("parsed tmux events: {:?}", &tmux_events); callback(Action::DeviceControl(DeviceControlMode::TmuxEvents(