* 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,
|
||||
};
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
enum StatusBarTextColor {
|
||||
White,
|
||||
Green,
|
||||
Orange,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
enum StatusBarTextBoldness {
|
||||
Bold,
|
||||
NotBold,
|
||||
}
|
||||
|
||||
fn full_length_shortcut(
|
||||
is_first_shortcut: bool,
|
||||
letter: &str,
|
||||
|
|
@ -100,55 +113,120 @@ fn locked_interface_indication(palette: Palette) -> LinePart {
|
|||
}
|
||||
}
|
||||
|
||||
fn select_pane_shortcut(is_first_shortcut: bool, palette: Palette) -> LinePart {
|
||||
let shortcut = "ENTER";
|
||||
let description = "Select pane";
|
||||
let separator = if is_first_shortcut { " " } else { " / " };
|
||||
fn show_extra_hints(
|
||||
palette: Palette,
|
||||
text_with_style: Vec<(&str, StatusBarTextColor, StatusBarTextBoldness)>,
|
||||
) -> LinePart {
|
||||
use StatusBarTextBoldness::*;
|
||||
use StatusBarTextColor::*;
|
||||
// get the colors
|
||||
let white_color = match palette.white {
|
||||
PaletteColor::Rgb((r, g, b)) => RGB(r, g, b),
|
||||
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 {
|
||||
PaletteColor::Rgb((r, g, b)) => RGB(r, g, b),
|
||||
PaletteColor::EightBit(color) => Fixed(color),
|
||||
};
|
||||
let separator = Style::new().fg(white_color).paint(separator);
|
||||
let shortcut_len = shortcut.chars().count() + 3; // 2 for <>'s around shortcut, 1 for the space
|
||||
let shortcut_left_separator = Style::new().fg(white_color).paint("<");
|
||||
let shortcut = Style::new().fg(orange_color).bold().paint(shortcut);
|
||||
let shortcut_right_separator = Style::new().fg(white_color).paint("> ");
|
||||
let description_len = description.chars().count();
|
||||
let description = Style::new().fg(white_color).bold().paint(description);
|
||||
let len = shortcut_len + description_len + separator.chars().count();
|
||||
// calculate length of tipp
|
||||
let len = text_with_style
|
||||
.iter()
|
||||
.fold(0, |len_sum, (text, _, _)| len_sum + text.chars().count());
|
||||
// apply the styles defined above
|
||||
let styled_text = text_with_style
|
||||
.into_iter()
|
||||
.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 {
|
||||
part: ANSIStrings(&[
|
||||
separator,
|
||||
shortcut_left_separator,
|
||||
shortcut,
|
||||
shortcut_right_separator,
|
||||
description,
|
||||
])
|
||||
.to_string(),
|
||||
part: ANSIStrings(&styled_text[..]).to_string(),
|
||||
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 {
|
||||
match help.mode {
|
||||
InputMode::Normal => tip(help.palette),
|
||||
InputMode::Locked => locked_interface_indication(help.palette),
|
||||
_ => {
|
||||
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 = select_pane_shortcut(help.keybinds.is_empty(), help.palette);
|
||||
line_part.len += select_pane_shortcut.len;
|
||||
line_part.part = format!("{}{}", line_part.part, select_pane_shortcut,);
|
||||
line_part
|
||||
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();
|
||||
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,);
|
||||
}
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -156,18 +234,35 @@ fn shortened_shortcut_list(help: &ModeInfo, tip: TipFn) -> LinePart {
|
|||
match help.mode {
|
||||
InputMode::Normal => tip(help.palette),
|
||||
InputMode::Locked => locked_interface_indication(help.palette),
|
||||
_ => {
|
||||
let mut line_part = LinePart::default();
|
||||
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,);
|
||||
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();
|
||||
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;
|
||||
}
|
||||
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.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()
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
let mut line_part = LinePart::default();
|
||||
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
|
||||
InputMode::RenamePane => {
|
||||
best_effort_shortcut_list_nonstandard_mode(select_pane_shortcut)(help, max_len)
|
||||
}
|
||||
_ => best_effort_shortcut_list_nonstandard_mode(confirm_pane_selection)(help, max_len),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue