mirror of
https://github.com/wez/wezterm.git
synced 2024-11-23 23:21:08 +03:00
tmux-cc: add support for layout-change (#972)
* tmux-cc: add support for layout-change * Test for client-session-changed * Tmux 3 * Handle visible_layout * Apply suggestions from code review Co-authored-by: Wez Furlong <wez@wezfurlong.org> * Fmt
This commit is contained in:
parent
dcbbda7702
commit
a7722273b0
@ -23,6 +23,13 @@ pub struct Guarded {
|
|||||||
pub output: String,
|
pub output: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
|
pub struct WindowLayout {
|
||||||
|
pub layout_id: String,
|
||||||
|
pub width: u64,
|
||||||
|
pub height: u64,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
pub enum Event {
|
pub enum Event {
|
||||||
Begin {
|
Begin {
|
||||||
@ -82,6 +89,12 @@ pub enum Event {
|
|||||||
window: TmuxWindowId,
|
window: TmuxWindowId,
|
||||||
name: String,
|
name: String,
|
||||||
},
|
},
|
||||||
|
LayoutChange {
|
||||||
|
window: TmuxWindowId,
|
||||||
|
layout: WindowLayout,
|
||||||
|
visible_layout: Option<WindowLayout>,
|
||||||
|
raw_flags: Option<String>,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_pane_id(pair: Pair<Rule>) -> anyhow::Result<TmuxPaneId> {
|
fn parse_pane_id(pair: Pair<Rule>) -> anyhow::Result<TmuxPaneId> {
|
||||||
@ -143,6 +156,29 @@ fn parse_guard(mut pairs: Pairs<Rule>) -> anyhow::Result<(i64, u64, i64)> {
|
|||||||
Ok((timestamp, number, flags))
|
Ok((timestamp, number, flags))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Parses a window_layout line, for example "b25d,80x24,0,0,0"
|
||||||
|
fn parse_window_layout(pair: Pair<Rule>) -> Option<WindowLayout> {
|
||||||
|
match pair.as_rule() {
|
||||||
|
Rule::window_layout => {
|
||||||
|
let mut pairs = pair.into_inner();
|
||||||
|
let layout_id_option = pairs.next()?.as_str().parse::<String>().ok();
|
||||||
|
let width_option = pairs.next()?.as_str().parse::<u64>().ok();
|
||||||
|
let height_option = pairs.next()?.as_str().parse::<u64>().ok();
|
||||||
|
if let (Some(layout_id), Some(width), Some(height)) =
|
||||||
|
(layout_id_option, width_option, height_option)
|
||||||
|
{
|
||||||
|
return Some(WindowLayout {
|
||||||
|
layout_id,
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn parse_line(line: &str) -> anyhow::Result<Event> {
|
fn parse_line(line: &str) -> anyhow::Result<Event> {
|
||||||
let mut pairs = parser::TmuxParser::parse(Rule::line_entire, line)?;
|
let mut pairs = parser::TmuxParser::parse(Rule::line_entire, line)?;
|
||||||
let pair = pairs.next().ok_or_else(|| anyhow::anyhow!("no pairs!?"))?;
|
let pair = pairs.next().ok_or_else(|| anyhow::anyhow!("no pairs!?"))?;
|
||||||
@ -238,11 +274,25 @@ fn parse_line(line: &str) -> anyhow::Result<Event> {
|
|||||||
let window = parse_window_id(pairs.next().unwrap())?;
|
let window = parse_window_id(pairs.next().unwrap())?;
|
||||||
Ok(Event::SessionWindowChanged { session, window })
|
Ok(Event::SessionWindowChanged { session, window })
|
||||||
}
|
}
|
||||||
|
Rule::layout_change => {
|
||||||
|
let mut pairs = pair.into_inner();
|
||||||
|
let window = parse_window_id(pairs.next().unwrap())?;
|
||||||
|
let layout = pairs.next().and_then(parse_window_layout).unwrap();
|
||||||
|
let visible_layout = pairs.next().and_then(parse_window_layout);
|
||||||
|
let raw_flags = pairs.next().map(|r| r.as_str().to_owned());
|
||||||
|
Ok(Event::LayoutChange {
|
||||||
|
window,
|
||||||
|
layout,
|
||||||
|
visible_layout,
|
||||||
|
raw_flags,
|
||||||
|
})
|
||||||
|
}
|
||||||
Rule::pane_id
|
Rule::pane_id
|
||||||
| Rule::word
|
| Rule::word
|
||||||
| Rule::client_name
|
| Rule::client_name
|
||||||
| Rule::window_id
|
| Rule::window_id
|
||||||
| Rule::session_id
|
| Rule::session_id
|
||||||
|
| Rule::window_layout
|
||||||
| Rule::any_text
|
| Rule::any_text
|
||||||
| Rule::line
|
| Rule::line
|
||||||
| Rule::line_entire
|
| Rule::line_entire
|
||||||
@ -596,6 +646,9 @@ here
|
|||||||
%window-add @1
|
%window-add @1
|
||||||
%sessions-changed
|
%sessions-changed
|
||||||
%session-changed $1 1
|
%session-changed $1 1
|
||||||
|
%client-session-changed /dev/pts/5 $1 home
|
||||||
|
%layout-change @1 b25d,80x24,0,0,0
|
||||||
|
%layout-change @1 cafd,120x29,0,0,0 cafd,120x29,0,0,0 *
|
||||||
%output %1 \\033[1m\\033[7m%\\033[27m\\033[1m\\033[0m \\015 \\015
|
%output %1 \\033[1m\\033[7m%\\033[27m\\033[1m\\033[0m \\015 \\015
|
||||||
%output %1 \\033kwez@cube-localdomain:~\\033\\134\\033]2;wez@cube-localdomain:~\\033\\134
|
%output %1 \\033kwez@cube-localdomain:~\\033\\134\\033]2;wez@cube-localdomain:~\\033\\134
|
||||||
%output %1 \\033]7;file://cube-localdomain/home/wez\\033\\134
|
%output %1 \\033]7;file://cube-localdomain/home/wez\\033\\134
|
||||||
@ -623,6 +676,35 @@ here
|
|||||||
session: 1,
|
session: 1,
|
||||||
name: "1".to_owned(),
|
name: "1".to_owned(),
|
||||||
},
|
},
|
||||||
|
Event::ClientSessionChanged {
|
||||||
|
client_name: "/dev/pts/5".to_owned(),
|
||||||
|
session: 1,
|
||||||
|
session_name: "home".to_owned()
|
||||||
|
},
|
||||||
|
Event::LayoutChange {
|
||||||
|
window: 1,
|
||||||
|
layout: WindowLayout {
|
||||||
|
layout_id: "b25d".to_owned(),
|
||||||
|
width: 80,
|
||||||
|
height: 24
|
||||||
|
},
|
||||||
|
visible_layout: None,
|
||||||
|
raw_flags: None
|
||||||
|
},
|
||||||
|
Event::LayoutChange {
|
||||||
|
window: 1,
|
||||||
|
layout: WindowLayout {
|
||||||
|
layout_id: "cafd".to_owned(),
|
||||||
|
width: 120,
|
||||||
|
height: 29
|
||||||
|
},
|
||||||
|
visible_layout: Some(WindowLayout {
|
||||||
|
layout_id: "cafd".to_owned(),
|
||||||
|
width: 120,
|
||||||
|
height: 29
|
||||||
|
}),
|
||||||
|
raw_flags: Some("*".to_owned())
|
||||||
|
},
|
||||||
Event::Output {
|
Event::Output {
|
||||||
pane: 1,
|
pane: 1,
|
||||||
text: "\x1b[1m\x1b[7m%\x1b[27m\x1b[1m\x1b[0m \r \r".to_owned()
|
text: "\x1b[1m\x1b[7m%\x1b[27m\x1b[1m\x1b[0m \r \r".to_owned()
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
number = { ASCII_DIGIT+ }
|
number = { ASCII_DIGIT+ }
|
||||||
any_text = { ANY* }
|
any_text = { ANY* }
|
||||||
word = { ASCII_ALPHANUMERIC+ }
|
word = { (ASCII_ALPHANUMERIC | "/")+ }
|
||||||
|
|
||||||
pane_id = { "%" ~ number }
|
pane_id = { "%" ~ number }
|
||||||
window_id = { "@" ~ number }
|
window_id = { "@" ~ number }
|
||||||
session_id = { "$" ~ number }
|
session_id = { "$" ~ number }
|
||||||
client_name = { word }
|
client_name = { word }
|
||||||
|
window_layout = { word ~ "," ~ number ~ "x" ~ number ~ "," ~ number ~ "," ~ number ~ "," ~ number }
|
||||||
|
|
||||||
begin = { "%begin " ~ number ~ " " ~ number ~ " " ~ number }
|
begin = { "%begin " ~ number ~ " " ~ number ~ " " ~ number }
|
||||||
end = { "%end " ~ number ~ " " ~ number ~ " " ~ number }
|
end = { "%end " ~ number ~ " " ~ number ~ " " ~ number }
|
||||||
@ -23,6 +24,7 @@ window_renamed = { "%window-renamed " ~ window_id ~ " " ~ any_text }
|
|||||||
session_changed = { "%session-changed " ~ session_id ~ " " ~ any_text }
|
session_changed = { "%session-changed " ~ session_id ~ " " ~ any_text }
|
||||||
session_renamed = { "%session-renamed " ~ any_text }
|
session_renamed = { "%session-renamed " ~ any_text }
|
||||||
session_window_changed = { "%session-window-changed " ~ session_id ~ " " ~ window_id }
|
session_window_changed = { "%session-window-changed " ~ session_id ~ " " ~ window_id }
|
||||||
|
layout_change = { "%layout-change " ~ window_id ~ " " ~ (window_layout ~ " " ~ window_layout ~ " " ~any_text | window_layout) }
|
||||||
|
|
||||||
line = _{ (
|
line = _{ (
|
||||||
client_session_changed |
|
client_session_changed |
|
||||||
@ -39,7 +41,8 @@ line = _{ (
|
|||||||
window_add |
|
window_add |
|
||||||
window_close |
|
window_close |
|
||||||
window_pane_changed |
|
window_pane_changed |
|
||||||
window_renamed
|
window_renamed |
|
||||||
|
layout_change
|
||||||
) }
|
) }
|
||||||
|
|
||||||
line_entire = _{ SOI ~ line ~ EOI }
|
line_entire = _{ SOI ~ line ~ EOI }
|
||||||
|
Loading…
Reference in New Issue
Block a user