* solve issue #1010 and made code easily extensible * Make description bold to fit + added minimal documentation * chore(assets): update plugins * Only change hints on reneamPane Mode, old hints were fine in every other case * fixing some wording to get more green e2e tests * add the opt version of the plugin Co-authored-by: jaeheonji <atx6419@gmail.com>
This commit is contained in:
parent
ff8616280b
commit
341a9f4b91
2 changed files with 137 additions and 58 deletions
Binary file not shown.
|
|
@ -10,6 +10,19 @@ use crate::{
|
||||||
LinePart, MORE_MSG,
|
LinePart, MORE_MSG,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#[derive(Clone, Copy)]
|
||||||
|
enum StatusBarTextColor {
|
||||||
|
White,
|
||||||
|
Green,
|
||||||
|
Orange,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Copy)]
|
||||||
|
enum StatusBarTextBoldness {
|
||||||
|
Bold,
|
||||||
|
NotBold,
|
||||||
|
}
|
||||||
|
|
||||||
fn full_length_shortcut(
|
fn full_length_shortcut(
|
||||||
is_first_shortcut: bool,
|
is_first_shortcut: bool,
|
||||||
letter: &str,
|
letter: &str,
|
||||||
|
|
@ -100,74 +113,156 @@ fn locked_interface_indication(palette: Palette) -> LinePart {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn select_pane_shortcut(is_first_shortcut: bool, palette: Palette) -> LinePart {
|
fn show_extra_hints(
|
||||||
let shortcut = "ENTER";
|
palette: Palette,
|
||||||
let description = "Select pane";
|
text_with_style: Vec<(&str, StatusBarTextColor, StatusBarTextBoldness)>,
|
||||||
let separator = if is_first_shortcut { " " } else { " / " };
|
) -> LinePart {
|
||||||
|
use StatusBarTextBoldness::*;
|
||||||
|
use StatusBarTextColor::*;
|
||||||
|
// get the colors
|
||||||
let white_color = match palette.white {
|
let white_color = match palette.white {
|
||||||
PaletteColor::Rgb((r, g, b)) => RGB(r, g, b),
|
PaletteColor::Rgb((r, g, b)) => RGB(r, g, b),
|
||||||
PaletteColor::EightBit(color) => Fixed(color),
|
PaletteColor::EightBit(color) => Fixed(color),
|
||||||
};
|
};
|
||||||
|
let green_color = match palette.green {
|
||||||
|
PaletteColor::Rgb((r, g, b)) => RGB(r, g, b),
|
||||||
|
PaletteColor::EightBit(color) => Fixed(color),
|
||||||
|
};
|
||||||
let orange_color = match palette.orange {
|
let orange_color = match palette.orange {
|
||||||
PaletteColor::Rgb((r, g, b)) => RGB(r, g, b),
|
PaletteColor::Rgb((r, g, b)) => RGB(r, g, b),
|
||||||
PaletteColor::EightBit(color) => Fixed(color),
|
PaletteColor::EightBit(color) => Fixed(color),
|
||||||
};
|
};
|
||||||
let separator = Style::new().fg(white_color).paint(separator);
|
// calculate length of tipp
|
||||||
let shortcut_len = shortcut.chars().count() + 3; // 2 for <>'s around shortcut, 1 for the space
|
let len = text_with_style
|
||||||
let shortcut_left_separator = Style::new().fg(white_color).paint("<");
|
.iter()
|
||||||
let shortcut = Style::new().fg(orange_color).bold().paint(shortcut);
|
.fold(0, |len_sum, (text, _, _)| len_sum + text.chars().count());
|
||||||
let shortcut_right_separator = Style::new().fg(white_color).paint("> ");
|
// apply the styles defined above
|
||||||
let description_len = description.chars().count();
|
let styled_text = text_with_style
|
||||||
let description = Style::new().fg(white_color).bold().paint(description);
|
.into_iter()
|
||||||
let len = shortcut_len + description_len + separator.chars().count();
|
.map(|(text, color, is_bold)| {
|
||||||
|
let color = match color {
|
||||||
|
White => white_color,
|
||||||
|
Green => green_color,
|
||||||
|
Orange => orange_color,
|
||||||
|
};
|
||||||
|
match is_bold {
|
||||||
|
Bold => Style::new().fg(color).bold().paint(text),
|
||||||
|
NotBold => Style::new().fg(color).paint(text),
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.collect::<Vec<_>>();
|
||||||
LinePart {
|
LinePart {
|
||||||
part: ANSIStrings(&[
|
part: ANSIStrings(&styled_text[..]).to_string(),
|
||||||
separator,
|
|
||||||
shortcut_left_separator,
|
|
||||||
shortcut,
|
|
||||||
shortcut_right_separator,
|
|
||||||
description,
|
|
||||||
])
|
|
||||||
.to_string(),
|
|
||||||
len,
|
len,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Creates hints for usage of Pane Mode
|
||||||
|
fn confirm_pane_selection(palette: Palette) -> LinePart {
|
||||||
|
use StatusBarTextBoldness::*;
|
||||||
|
use StatusBarTextColor::*;
|
||||||
|
let text_with_style = [
|
||||||
|
(" / ", White, NotBold),
|
||||||
|
("<ENTER>", Green, Bold),
|
||||||
|
(" Select pane", White, Bold),
|
||||||
|
];
|
||||||
|
show_extra_hints(palette, text_with_style.to_vec())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Creates hints for usage of Rename Mode in Pane Mode
|
||||||
|
fn select_pane_shortcut(palette: Palette) -> LinePart {
|
||||||
|
use StatusBarTextBoldness::*;
|
||||||
|
use StatusBarTextColor::*;
|
||||||
|
let text_with_style = [
|
||||||
|
(" / ", White, NotBold),
|
||||||
|
("Alt", Orange, Bold),
|
||||||
|
(" + ", White, NotBold),
|
||||||
|
("<", Green, Bold),
|
||||||
|
("[]", Green, Bold),
|
||||||
|
(" or ", White, NotBold),
|
||||||
|
("hjkl", Green, Bold),
|
||||||
|
(">", Green, Bold),
|
||||||
|
(" Select pane", White, Bold),
|
||||||
|
];
|
||||||
|
show_extra_hints(palette, text_with_style.to_vec())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn full_shortcut_list_nonstandard_mode(
|
||||||
|
extra_hint_producing_function: fn(Palette) -> LinePart,
|
||||||
|
) -> impl FnOnce(&ModeInfo) -> LinePart {
|
||||||
|
move |help| {
|
||||||
|
let mut line_part = LinePart::default();
|
||||||
|
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,);
|
||||||
|
}
|
||||||
|
let select_pane_shortcut = extra_hint_producing_function(help.palette);
|
||||||
|
line_part.len += select_pane_shortcut.len;
|
||||||
|
line_part.part = format!("{}{}", line_part.part, select_pane_shortcut,);
|
||||||
|
line_part
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn full_shortcut_list(help: &ModeInfo, tip: TipFn) -> LinePart {
|
fn full_shortcut_list(help: &ModeInfo, tip: TipFn) -> LinePart {
|
||||||
match help.mode {
|
match help.mode {
|
||||||
InputMode::Normal => tip(help.palette),
|
InputMode::Normal => tip(help.palette),
|
||||||
InputMode::Locked => locked_interface_indication(help.palette),
|
InputMode::Locked => locked_interface_indication(help.palette),
|
||||||
_ => {
|
InputMode::RenamePane => full_shortcut_list_nonstandard_mode(select_pane_shortcut)(help),
|
||||||
|
_ => full_shortcut_list_nonstandard_mode(confirm_pane_selection)(help),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn shortened_shortcut_list_nonstandard_mode(
|
||||||
|
extra_hint_producing_function: fn(Palette) -> LinePart,
|
||||||
|
) -> impl FnOnce(&ModeInfo) -> LinePart {
|
||||||
|
move |help| {
|
||||||
let mut line_part = LinePart::default();
|
let mut line_part = LinePart::default();
|
||||||
for (i, (letter, description)) in help.keybinds.iter().enumerate() {
|
for (i, (letter, description)) in help.keybinds.iter().enumerate() {
|
||||||
let shortcut = full_length_shortcut(i == 0, letter, description, help.palette);
|
let shortcut = first_word_shortcut(i == 0, letter, description, help.palette);
|
||||||
line_part.len += shortcut.len;
|
line_part.len += shortcut.len;
|
||||||
line_part.part = format!("{}{}", line_part.part, shortcut,);
|
line_part.part = format!("{}{}", line_part.part, shortcut,);
|
||||||
}
|
}
|
||||||
let select_pane_shortcut = select_pane_shortcut(help.keybinds.is_empty(), help.palette);
|
let select_pane_shortcut = extra_hint_producing_function(help.palette);
|
||||||
line_part.len += select_pane_shortcut.len;
|
line_part.len += select_pane_shortcut.len;
|
||||||
line_part.part = format!("{}{}", line_part.part, select_pane_shortcut,);
|
line_part.part = format!("{}{}", line_part.part, select_pane_shortcut,);
|
||||||
line_part
|
line_part
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn shortened_shortcut_list(help: &ModeInfo, tip: TipFn) -> LinePart {
|
fn shortened_shortcut_list(help: &ModeInfo, tip: TipFn) -> LinePart {
|
||||||
match help.mode {
|
match help.mode {
|
||||||
InputMode::Normal => tip(help.palette),
|
InputMode::Normal => tip(help.palette),
|
||||||
InputMode::Locked => locked_interface_indication(help.palette),
|
InputMode::Locked => locked_interface_indication(help.palette),
|
||||||
_ => {
|
InputMode::RenamePane => {
|
||||||
|
shortened_shortcut_list_nonstandard_mode(select_pane_shortcut)(help)
|
||||||
|
}
|
||||||
|
_ => shortened_shortcut_list_nonstandard_mode(confirm_pane_selection)(help),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn best_effort_shortcut_list_nonstandard_mode(
|
||||||
|
extra_hint_producing_function: fn(Palette) -> LinePart,
|
||||||
|
) -> impl FnOnce(&ModeInfo, usize) -> LinePart {
|
||||||
|
move |help, max_len| {
|
||||||
let mut line_part = LinePart::default();
|
let mut line_part = LinePart::default();
|
||||||
for (i, (letter, description)) in help.keybinds.iter().enumerate() {
|
for (i, (letter, description)) in help.keybinds.iter().enumerate() {
|
||||||
let shortcut = first_word_shortcut(i == 0, letter, description, help.palette);
|
let shortcut = first_word_shortcut(i == 0, letter, description, help.palette);
|
||||||
line_part.len += shortcut.len;
|
if line_part.len + shortcut.len + MORE_MSG.chars().count() > max_len {
|
||||||
line_part.part = format!("{}{}", line_part.part, shortcut,);
|
// TODO: better
|
||||||
|
line_part.part = format!("{}{}", line_part.part, MORE_MSG);
|
||||||
|
line_part.len += MORE_MSG.chars().count();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
let select_pane_shortcut = select_pane_shortcut(help.keybinds.is_empty(), help.palette);
|
line_part.len += shortcut.len;
|
||||||
|
line_part.part = format!("{}{}", line_part.part, shortcut);
|
||||||
|
}
|
||||||
|
let select_pane_shortcut = extra_hint_producing_function(help.palette);
|
||||||
|
if line_part.len + select_pane_shortcut.len <= max_len {
|
||||||
line_part.len += select_pane_shortcut.len;
|
line_part.len += select_pane_shortcut.len;
|
||||||
line_part.part = format!("{}{}", line_part.part, select_pane_shortcut,);
|
line_part.part = format!("{}{}", line_part.part, select_pane_shortcut,);
|
||||||
line_part
|
|
||||||
}
|
}
|
||||||
|
line_part
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -189,26 +284,10 @@ fn best_effort_shortcut_list(help: &ModeInfo, tip: TipFn, max_len: usize) -> Lin
|
||||||
LinePart::default()
|
LinePart::default()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {
|
InputMode::RenamePane => {
|
||||||
let mut line_part = LinePart::default();
|
best_effort_shortcut_list_nonstandard_mode(select_pane_shortcut)(help, max_len)
|
||||||
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);
|
|
||||||
}
|
|
||||||
let select_pane_shortcut = select_pane_shortcut(help.keybinds.is_empty(), help.palette);
|
|
||||||
if line_part.len + select_pane_shortcut.len <= max_len {
|
|
||||||
line_part.len += select_pane_shortcut.len;
|
|
||||||
line_part.part = format!("{}{}", line_part.part, select_pane_shortcut,);
|
|
||||||
}
|
|
||||||
line_part
|
|
||||||
}
|
}
|
||||||
|
_ => best_effort_shortcut_list_nonstandard_mode(confirm_pane_selection)(help, max_len),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue