From a0a0a7e5c4e6fccc755fb5199f7f3b853e7b3746 Mon Sep 17 00:00:00 2001 From: Aram Drevekenin Date: Mon, 21 Feb 2022 15:52:42 +0100 Subject: feat(ux): tmux mode (#1073) * work * basic tmux move and functionality * tmux mode ui * rustfmt --- default-plugins/status-bar/src/first_line.rs | 15 ++++ default-plugins/status-bar/src/second_line.rs | 103 ++++++++++++++++++++++++++ 2 files changed, 118 insertions(+) (limited to 'default-plugins') diff --git a/default-plugins/status-bar/src/first_line.rs b/default-plugins/status-bar/src/first_line.rs index cdb1decee..ed67e5cc5 100644 --- a/default-plugins/status-bar/src/first_line.rs +++ b/default-plugins/status-bar/src/first_line.rs @@ -369,5 +369,20 @@ pub fn ctrl_keys(help: &ModeInfo, max_len: usize, separator: &str) -> LinePart { colored_elements, separator, ), + InputMode::Tmux => key_indicators( + max_len, + &[ + CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Lock), + CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Pane), + CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Tab), + CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Resize), + CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Move), + CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Scroll), + CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Session), + CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Quit), + ], + colored_elements, + separator, + ), } } diff --git a/default-plugins/status-bar/src/second_line.rs b/default-plugins/status-bar/src/second_line.rs index abd2f8c3f..d33efc02e 100644 --- a/default-plugins/status-bar/src/second_line.rs +++ b/default-plugins/status-bar/src/second_line.rs @@ -208,6 +208,7 @@ fn full_shortcut_list(help: &ModeInfo, tip: TipFn) -> LinePart { match help.mode { InputMode::Normal => tip(help.palette), InputMode::Locked => locked_interface_indication(help.palette), + InputMode::Tmux => full_tmux_mode_indication(help), InputMode::RenamePane => full_shortcut_list_nonstandard_mode(select_pane_shortcut)(help), _ => full_shortcut_list_nonstandard_mode(confirm_pane_selection)(help), } @@ -234,6 +235,7 @@ fn shortened_shortcut_list(help: &ModeInfo, tip: TipFn) -> LinePart { match help.mode { InputMode::Normal => tip(help.palette), InputMode::Locked => locked_interface_indication(help.palette), + InputMode::Tmux => short_tmux_mode_indication(help), InputMode::RenamePane => { shortened_shortcut_list_nonstandard_mode(select_pane_shortcut)(help) } @@ -266,6 +268,22 @@ fn best_effort_shortcut_list_nonstandard_mode( } } +fn best_effort_tmux_shortcut_list(help: &ModeInfo, max_len: usize) -> LinePart { + let mut line_part = tmux_mode_indication(help); + for (i, (letter, description)) in help.keybinds.iter().enumerate() { + let shortcut = first_word_shortcut(i == 0, letter, description, help.palette); + if line_part.len + shortcut.len + MORE_MSG.chars().count() > max_len { + // TODO: better + line_part.part = format!("{}{}", line_part.part, MORE_MSG); + line_part.len += MORE_MSG.chars().count(); + break; + } + line_part.len += shortcut.len; + line_part.part = format!("{}{}", line_part.part, shortcut); + } + line_part +} + fn best_effort_shortcut_list(help: &ModeInfo, tip: TipFn, max_len: usize) -> LinePart { match help.mode { InputMode::Normal => { @@ -284,6 +302,7 @@ fn best_effort_shortcut_list(help: &ModeInfo, tip: TipFn, max_len: usize) -> Lin LinePart::default() } } + InputMode::Tmux => best_effort_tmux_shortcut_list(help, max_len), InputMode::RenamePane => { best_effort_shortcut_list_nonstandard_mode(select_pane_shortcut)(help, max_len) } @@ -377,6 +396,90 @@ pub fn fullscreen_panes_to_hide(palette: &Palette, panes_to_hide: usize) -> Line } } +pub fn tmux_mode_indication(help: &ModeInfo) -> LinePart { + let white_color = match help.palette.white { + PaletteColor::Rgb((r, g, b)) => RGB(r, g, b), + PaletteColor::EightBit(color) => Fixed(color), + }; + let orange_color = match help.palette.orange { + PaletteColor::Rgb((r, g, b)) => RGB(r, g, b), + PaletteColor::EightBit(color) => Fixed(color), + }; + + let shortcut_left_separator = Style::new().fg(white_color).bold().paint(" ("); + let shortcut_right_separator = Style::new().fg(white_color).bold().paint("): "); + let tmux_mode_text = "TMUX MODE"; + let tmux_mode_indicator = Style::new().fg(orange_color).bold().paint(tmux_mode_text); + let line_part = LinePart { + part: format!( + "{}{}{}", + shortcut_left_separator, tmux_mode_indicator, shortcut_right_separator + ), + len: tmux_mode_text.chars().count() + 5, // 2 for the separators, 3 for the colon and following space + }; + line_part +} + +pub fn full_tmux_mode_indication(help: &ModeInfo) -> LinePart { + let white_color = match help.palette.white { + PaletteColor::Rgb((r, g, b)) => RGB(r, g, b), + PaletteColor::EightBit(color) => Fixed(color), + }; + let orange_color = match help.palette.orange { + PaletteColor::Rgb((r, g, b)) => RGB(r, g, b), + PaletteColor::EightBit(color) => Fixed(color), + }; + + let shortcut_left_separator = Style::new().fg(white_color).bold().paint(" ("); + let shortcut_right_separator = Style::new().fg(white_color).bold().paint("): "); + let tmux_mode_text = "TMUX MODE"; + let tmux_mode_indicator = Style::new().fg(orange_color).bold().paint(tmux_mode_text); + let mut line_part = LinePart { + part: format!( + "{}{}{}", + shortcut_left_separator, tmux_mode_indicator, shortcut_right_separator + ), + len: tmux_mode_text.chars().count() + 5, // 2 for the separators, 3 for the colon and following space + }; + + for (i, (letter, description)) in help.keybinds.iter().enumerate() { + let shortcut = full_length_shortcut(i == 0, letter, description, help.palette); + line_part.len += shortcut.len; + line_part.part = format!("{}{}", line_part.part, shortcut,); + } + line_part +} + +pub fn short_tmux_mode_indication(help: &ModeInfo) -> LinePart { + let white_color = match help.palette.white { + PaletteColor::Rgb((r, g, b)) => RGB(r, g, b), + PaletteColor::EightBit(color) => Fixed(color), + }; + let orange_color = match help.palette.orange { + PaletteColor::Rgb((r, g, b)) => RGB(r, g, b), + PaletteColor::EightBit(color) => Fixed(color), + }; + + let shortcut_left_separator = Style::new().fg(white_color).bold().paint(" ("); + let shortcut_right_separator = Style::new().fg(white_color).bold().paint("): "); + let tmux_mode_text = "TMUX MODE"; + let tmux_mode_indicator = Style::new().fg(orange_color).bold().paint(tmux_mode_text); + let mut line_part = LinePart { + part: format!( + "{}{}{}", + shortcut_left_separator, tmux_mode_indicator, shortcut_right_separator + ), + len: tmux_mode_text.chars().count() + 5, // 2 for the separators, 3 for the colon and following space + }; + + for (i, (letter, description)) in help.keybinds.iter().enumerate() { + let shortcut = first_word_shortcut(i == 0, letter, description, help.palette); + line_part.len += shortcut.len; + line_part.part = format!("{}{}", line_part.part, shortcut); + } + line_part +} + pub fn locked_fullscreen_panes_to_hide(palette: &Palette, panes_to_hide: usize) -> LinePart { let white_color = match palette.white { PaletteColor::Rgb((r, g, b)) => RGB(r, g, b), -- cgit v1.2.3