1
1
mirror of https://github.com/wez/wezterm.git synced 2024-12-27 15:37:29 +03:00

split out tmux commands

This commit is contained in:
g4c 2021-08-23 20:48:09 +08:00 committed by Wez Furlong
parent 18dd3e90bc
commit 8e04f49d03
4 changed files with 100 additions and 95 deletions

2
Cargo.lock generated
View File

@ -2297,6 +2297,7 @@ dependencies = [
"crossbeam",
"downcast-rs",
"filedescriptor",
"flume",
"hostname",
"k9",
"lazy_static",
@ -4111,6 +4112,7 @@ dependencies = [
"terminfo",
"termios 0.3.3",
"thiserror",
"tmux-cc",
"ucd-trie",
"unicode-segmentation",
"varbincode",

View File

@ -38,6 +38,7 @@ pub mod ssh;
pub mod tab;
pub mod termwiztermtab;
pub mod tmux;
pub mod tmux_commands;
pub mod window;
use crate::activity::Activity;

View File

@ -1,7 +1,9 @@
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::window::WindowId;
use crate::Mux;
use anyhow::anyhow;
use async_trait::async_trait;
use flume;
use portable_pty::{CommandBuilder, PtySize};
@ -18,100 +20,6 @@ enum State {
WaitingForResponse,
}
trait TmuxCommand {
fn get_command(&self) -> String;
fn process_result(&self, domain_id: DomainId, result: &Guarded) -> anyhow::Result<()>;
}
struct ListAllPanes;
impl TmuxCommand for ListAllPanes {
fn get_command(&self) -> String {
"list-panes -aF '#{session_id} #{window_id} #{pane_id} \
#{pane_index} #{cursor_x} #{cursor_y} #{pane_width} #{pane_height} \
#{pane_left} #{pane_top}'\n"
.to_owned()
}
fn process_result(&self, domain_id: DomainId, result: &Guarded) -> anyhow::Result<()> {
#[derive(Debug)]
#[allow(dead_code)]
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,
}
let mut items = vec![];
for line in result.output.split('\n') {
if line.is_empty() {
continue;
}
let mut fields = line.split(' ');
let session_id = fields.next().ok_or_else(|| anyhow!("missing session_id"))?;
let window_id = fields.next().ok_or_else(|| anyhow!("missing window_id"))?;
let pane_id = fields.next().ok_or_else(|| anyhow!("missing pane_id"))?;
let pane_index = fields
.next()
.ok_or_else(|| anyhow!("missing pane_index"))?
.parse()?;
let cursor_x = fields
.next()
.ok_or_else(|| anyhow!("missing cursor_x"))?
.parse()?;
let cursor_y = fields
.next()
.ok_or_else(|| anyhow!("missing cursor_y"))?
.parse()?;
let pane_width = fields
.next()
.ok_or_else(|| anyhow!("missing pane_width"))?
.parse()?;
let pane_height = fields
.next()
.ok_or_else(|| anyhow!("missing pane_height"))?
.parse()?;
let pane_left = fields
.next()
.ok_or_else(|| anyhow!("missing pane_left"))?
.parse()?;
let pane_top = fields
.next()
.ok_or_else(|| anyhow!("missing pane_top"))?
.parse()?;
// These ids all have various sigils such as `$`, `%`, `@`,
// so skip those prior to parsing them
let session_id = session_id[1..].parse()?;
let window_id = window_id[1..].parse()?;
let pane_id = pane_id[1..].parse()?;
items.push(Item {
session_id,
window_id,
pane_id,
pane_index,
cursor_x,
cursor_y,
pane_width,
pane_height,
pane_left,
pane_top,
});
}
log::error!("panes in domain_id {}: {:?}", domain_id, items);
Ok(())
}
}
struct TmuxRemotePane {
// members for local
local_pane_id: PaneId,

View File

@ -0,0 +1,94 @@
use anyhow::anyhow;
pub(crate) trait TmuxCommand {
fn get_command(&self) -> String;
fn process_result(&self, domain_id: DomainId, result: &Guarded) -> anyhow::Result<()>;
}
pub(crate) struct ListAllPanes;
impl TmuxCommand for ListAllPanes {
fn get_command(&self) -> String {
"list-panes -aF '#{session_id} #{window_id} #{pane_id} \
#{pane_index} #{cursor_x} #{cursor_y} #{pane_width} #{pane_height} \
#{pane_left} #{pane_top}'\n"
.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,
}
let mut items = vec![];
for line in result.output.split('\n') {
if line.is_empty() {
continue;
}
let mut fields = line.split(' ');
let session_id = fields.next().ok_or_else(|| anyhow!("missing session_id"))?;
let window_id = fields.next().ok_or_else(|| anyhow!("missing window_id"))?;
let pane_id = fields.next().ok_or_else(|| anyhow!("missing pane_id"))?;
let pane_index = fields
.next()
.ok_or_else(|| anyhow!("missing pane_index"))?
.parse()?;
let cursor_x = fields
.next()
.ok_or_else(|| anyhow!("missing cursor_x"))?
.parse()?;
let cursor_y = fields
.next()
.ok_or_else(|| anyhow!("missing cursor_y"))?
.parse()?;
let pane_width = fields
.next()
.ok_or_else(|| anyhow!("missing pane_width"))?
.parse()?;
let pane_height = fields
.next()
.ok_or_else(|| anyhow!("missing pane_height"))?
.parse()?;
let pane_left = fields
.next()
.ok_or_else(|| anyhow!("missing pane_left"))?
.parse()?;
let pane_top = fields
.next()
.ok_or_else(|| anyhow!("missing pane_top"))?
.parse()?;
// These ids all have various sigils such as `$`, `%`, `@`,
// so skip those prior to parsing them
let session_id = session_id[1..].parse()?;
let window_id = window_id[1..].parse()?;
let pane_id = pane_id[1..].parse()?;
items.push(Item {
session_id,
window_id,
pane_id,
pane_index,
cursor_x,
cursor_y,
pane_width,
pane_height,
pane_left,
pane_top,
});
}
log::error!("panes in domain_id {}: {:?}", domain_id, items);
Ok(())
}
}