split out tmux command process
This commit is contained in:
1 parent
8e04f49d03
commit
007a0c1b27
3 files changed
+50
-21
No files matched your search
+6
-3
@@ -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();
|
||||
|
||||
+43
-18
@@ -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<TmuxCommandResult>;
|
||||
}
|
||||
|
||||
#[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<PaneItem>),
|
||||
}
|
||||
|
||||
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<TmuxCommandResult> {
|
||||
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::<TmuxDomain>() {
|
||||
// TODO:
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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(
|
||||
|
||||
Reference in new issue
Block a user