Fixing a load of clippy lints in status-bar

This commit is contained in:
Brooks J Rady 2021-03-25 17:41:02 +00:00
parent b6f945da35
commit 6316763b0e
3 changed files with 45 additions and 81 deletions

View file

@ -70,90 +70,64 @@ fn unselected_mode_shortcut(letter: char, text: &str) -> LinePart {
.fg(BLACK) .fg(BLACK)
.on(BRIGHT_GRAY) .on(BRIGHT_GRAY)
.bold() .bold()
.paint(format!(" <")); .paint(" <");
let char_shortcut = Style::new() let char_shortcut = Style::new()
.bold() .bold()
.fg(RED) .fg(RED)
.on(BRIGHT_GRAY) .on(BRIGHT_GRAY)
.bold() .bold()
.paint(format!("{}", letter)); .paint(letter.to_string());
let char_right_separator = Style::new() let char_right_separator = Style::new()
.bold() .bold()
.fg(BLACK) .fg(BLACK)
.on(BRIGHT_GRAY) .on(BRIGHT_GRAY)
.bold() .bold()
.paint(format!(">")); .paint(">");
let styled_text = Style::new() let styled_text = Style::new().fg(BLACK).on(BRIGHT_GRAY).bold().paint(text);
.fg(BLACK)
.on(BRIGHT_GRAY)
.bold()
.paint(format!("{} ", text));
let suffix_separator = Style::new().fg(BRIGHT_GRAY).on(GRAY).paint(ARROW_SEPARATOR); let suffix_separator = Style::new().fg(BRIGHT_GRAY).on(GRAY).paint(ARROW_SEPARATOR);
LinePart { LinePart {
part: format!( part: ANSIStrings(&[
"{}", prefix_separator,
ANSIStrings(&[ char_left_separator,
prefix_separator, char_shortcut,
char_left_separator, char_right_separator,
char_shortcut, styled_text,
char_right_separator, suffix_separator,
styled_text, ])
suffix_separator .to_string(),
])
),
len: text.chars().count() + 6, // 2 for the arrows, 3 for the char separators, 1 for the character len: text.chars().count() + 6, // 2 for the arrows, 3 for the char separators, 1 for the character
} }
} }
fn selected_mode_shortcut(letter: char, text: &str) -> LinePart { fn selected_mode_shortcut(letter: char, text: &str) -> LinePart {
let prefix_separator = Style::new().fg(GRAY).on(GREEN).paint(ARROW_SEPARATOR); let prefix_separator = Style::new().fg(GRAY).on(GREEN).paint(ARROW_SEPARATOR);
let char_left_separator = Style::new() let char_left_separator = Style::new().bold().fg(BLACK).on(GREEN).bold().paint(" <");
.bold()
.fg(BLACK)
.on(GREEN)
.bold()
.paint(format!(" <"));
let char_shortcut = Style::new() let char_shortcut = Style::new()
.bold() .bold()
.fg(RED) .fg(RED)
.on(GREEN) .on(GREEN)
.bold() .bold()
.paint(format!("{}", letter)); .paint(letter.to_string());
let char_right_separator = Style::new() let char_right_separator = Style::new().bold().fg(BLACK).on(GREEN).bold().paint(">");
.bold() let styled_text = Style::new().fg(BLACK).on(GREEN).bold().paint(text);
.fg(BLACK)
.on(GREEN)
.bold()
.paint(format!(">"));
let styled_text = Style::new()
.fg(BLACK)
.on(GREEN)
.bold()
.paint(format!("{} ", text));
let suffix_separator = Style::new().fg(GREEN).on(GRAY).paint(ARROW_SEPARATOR); let suffix_separator = Style::new().fg(GREEN).on(GRAY).paint(ARROW_SEPARATOR);
LinePart { LinePart {
part: format!( part: ANSIStrings(&[
"{}", prefix_separator,
ANSIStrings(&[ char_left_separator,
prefix_separator, char_shortcut,
char_left_separator, char_right_separator,
char_shortcut, styled_text,
char_right_separator, suffix_separator,
styled_text, ])
suffix_separator .to_string(),
])
),
len: text.chars().count() + 6, // 2 for the arrows, 3 for the char separators, 1 for the character len: text.chars().count() + 6, // 2 for the arrows, 3 for the char separators, 1 for the character
} }
} }
fn disabled_mode_shortcut(text: &str) -> LinePart { fn disabled_mode_shortcut(text: &str) -> LinePart {
let prefix_separator = Style::new().fg(GRAY).on(BRIGHT_GRAY).paint(ARROW_SEPARATOR); let prefix_separator = Style::new().fg(GRAY).on(BRIGHT_GRAY).paint(ARROW_SEPARATOR);
let styled_text = Style::new() let styled_text = Style::new().fg(GRAY).on(BRIGHT_GRAY).dimmed().paint(text);
.fg(GRAY)
.on(BRIGHT_GRAY)
.dimmed()
.paint(format!("{} ", text));
let suffix_separator = Style::new().fg(BRIGHT_GRAY).on(GRAY).paint(ARROW_SEPARATOR); let suffix_separator = Style::new().fg(BRIGHT_GRAY).on(GRAY).paint(ARROW_SEPARATOR);
LinePart { LinePart {
part: format!("{}{}{}", prefix_separator, styled_text, suffix_separator), part: format!("{}{}{}", prefix_separator, styled_text, suffix_separator),
@ -162,7 +136,7 @@ fn disabled_mode_shortcut(text: &str) -> LinePart {
} }
fn selected_mode_shortcut_single_letter(letter: char) -> LinePart { fn selected_mode_shortcut_single_letter(letter: char) -> LinePart {
let char_shortcut_text = format!(" {} ", letter); let char_shortcut_text = letter.to_string();
let len = char_shortcut_text.chars().count() + 4; // 2 for the arrows, 2 for the padding let len = char_shortcut_text.chars().count() + 4; // 2 for the arrows, 2 for the padding
let prefix_separator = Style::new().fg(GRAY).on(GREEN).paint(ARROW_SEPARATOR); let prefix_separator = Style::new().fg(GRAY).on(GREEN).paint(ARROW_SEPARATOR);
let char_shortcut = Style::new() let char_shortcut = Style::new()
@ -173,16 +147,13 @@ fn selected_mode_shortcut_single_letter(letter: char) -> LinePart {
.paint(char_shortcut_text); .paint(char_shortcut_text);
let suffix_separator = Style::new().fg(GREEN).on(GRAY).paint(ARROW_SEPARATOR); let suffix_separator = Style::new().fg(GREEN).on(GRAY).paint(ARROW_SEPARATOR);
LinePart { LinePart {
part: format!( part: ANSIStrings(&[prefix_separator, char_shortcut, suffix_separator]).to_string(),
"{}",
ANSIStrings(&[prefix_separator, char_shortcut, suffix_separator])
),
len, len,
} }
} }
fn unselected_mode_shortcut_single_letter(letter: char) -> LinePart { fn unselected_mode_shortcut_single_letter(letter: char) -> LinePart {
let char_shortcut_text = format!(" {} ", letter); let char_shortcut_text = letter.to_string();
let len = char_shortcut_text.chars().count() + 4; // 2 for the arrows, 2 for the padding let len = char_shortcut_text.chars().count() + 4; // 2 for the arrows, 2 for the padding
let prefix_separator = Style::new().fg(GRAY).on(BRIGHT_GRAY).paint(ARROW_SEPARATOR); let prefix_separator = Style::new().fg(GRAY).on(BRIGHT_GRAY).paint(ARROW_SEPARATOR);
let char_shortcut = Style::new() let char_shortcut = Style::new()
@ -193,10 +164,7 @@ fn unselected_mode_shortcut_single_letter(letter: char) -> LinePart {
.paint(char_shortcut_text); .paint(char_shortcut_text);
let suffix_separator = Style::new().fg(BRIGHT_GRAY).on(GRAY).paint(ARROW_SEPARATOR); let suffix_separator = Style::new().fg(BRIGHT_GRAY).on(GRAY).paint(ARROW_SEPARATOR);
LinePart { LinePart {
part: format!( part: ANSIStrings(&[prefix_separator, char_shortcut, suffix_separator]).to_string(),
"{}",
ANSIStrings(&[prefix_separator, char_shortcut, suffix_separator])
),
len, len,
} }
} }
@ -225,12 +193,8 @@ fn shortened_ctrl_key(key: &CtrlKeyShortcut) -> LinePart {
_ => shortened_text, _ => shortened_text,
}; };
match key.mode { match key.mode {
CtrlKeyMode::Unselected => { CtrlKeyMode::Unselected => unselected_mode_shortcut(letter_shortcut, &shortened_text),
unselected_mode_shortcut(letter_shortcut, &format!("{}", shortened_text)) CtrlKeyMode::Selected => selected_mode_shortcut(letter_shortcut, &shortened_text),
}
CtrlKeyMode::Selected => {
selected_mode_shortcut(letter_shortcut, &format!("{}", shortened_text))
}
CtrlKeyMode::Disabled => { CtrlKeyMode::Disabled => {
disabled_mode_shortcut(&format!(" <{}>{}", letter_shortcut, shortened_text)) disabled_mode_shortcut(&format!(" <{}>{}", letter_shortcut, shortened_text))
} }
@ -282,7 +246,7 @@ pub fn superkey() -> LinePart {
let prefix_text = " Ctrl + "; let prefix_text = " Ctrl + ";
let prefix = Style::new().fg(WHITE).on(GRAY).bold().paint(prefix_text); let prefix = Style::new().fg(WHITE).on(GRAY).bold().paint(prefix_text);
LinePart { LinePart {
part: format!("{}", prefix), part: prefix.to_string(),
len: prefix_text.chars().count(), len: prefix_text.chars().count(),
} }
} }
@ -291,7 +255,7 @@ pub fn ctrl_keys(help: &ModeInfo, max_len: usize) -> LinePart {
match &help.mode { match &help.mode {
InputMode::Locked => key_indicators( InputMode::Locked => key_indicators(
max_len, max_len,
&vec![ &[
CtrlKeyShortcut::new(CtrlKeyMode::Selected, CtrlKeyAction::Lock), CtrlKeyShortcut::new(CtrlKeyMode::Selected, CtrlKeyAction::Lock),
CtrlKeyShortcut::new(CtrlKeyMode::Disabled, CtrlKeyAction::Pane), CtrlKeyShortcut::new(CtrlKeyMode::Disabled, CtrlKeyAction::Pane),
CtrlKeyShortcut::new(CtrlKeyMode::Disabled, CtrlKeyAction::Tab), CtrlKeyShortcut::new(CtrlKeyMode::Disabled, CtrlKeyAction::Tab),
@ -302,7 +266,7 @@ pub fn ctrl_keys(help: &ModeInfo, max_len: usize) -> LinePart {
), ),
InputMode::Resize => key_indicators( InputMode::Resize => key_indicators(
max_len, max_len,
&vec![ &[
CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Lock), CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Lock),
CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Pane), CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Pane),
CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Tab), CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Tab),
@ -313,7 +277,7 @@ pub fn ctrl_keys(help: &ModeInfo, max_len: usize) -> LinePart {
), ),
InputMode::Pane => key_indicators( InputMode::Pane => key_indicators(
max_len, max_len,
&vec![ &[
CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Lock), CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Lock),
CtrlKeyShortcut::new(CtrlKeyMode::Selected, CtrlKeyAction::Pane), CtrlKeyShortcut::new(CtrlKeyMode::Selected, CtrlKeyAction::Pane),
CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Tab), CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Tab),
@ -324,7 +288,7 @@ pub fn ctrl_keys(help: &ModeInfo, max_len: usize) -> LinePart {
), ),
InputMode::Tab | InputMode::RenameTab => key_indicators( InputMode::Tab | InputMode::RenameTab => key_indicators(
max_len, max_len,
&vec![ &[
CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Lock), CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Lock),
CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Pane), CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Pane),
CtrlKeyShortcut::new(CtrlKeyMode::Selected, CtrlKeyAction::Tab), CtrlKeyShortcut::new(CtrlKeyMode::Selected, CtrlKeyAction::Tab),
@ -335,7 +299,7 @@ pub fn ctrl_keys(help: &ModeInfo, max_len: usize) -> LinePart {
), ),
InputMode::Scroll => key_indicators( InputMode::Scroll => key_indicators(
max_len, max_len,
&vec![ &[
CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Lock), CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Lock),
CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Pane), CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Pane),
CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Tab), CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Tab),
@ -346,7 +310,7 @@ pub fn ctrl_keys(help: &ModeInfo, max_len: usize) -> LinePart {
), ),
InputMode::Normal => key_indicators( InputMode::Normal => key_indicators(
max_len, max_len,
&vec![ &[
CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Lock), CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Lock),
CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Pane), CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Pane),
CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Tab), CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Tab),

View file

@ -108,7 +108,7 @@ fn full_shortcut_list(help: &ModeInfo) -> LinePart {
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.len() == 0); let select_pane_shortcut = select_pane_shortcut(help.keybinds.is_empty());
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
@ -127,7 +127,7 @@ fn shortened_shortcut_list(help: &ModeInfo) -> LinePart {
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.len() == 0); let select_pane_shortcut = select_pane_shortcut(help.keybinds.is_empty());
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
@ -159,7 +159,7 @@ fn best_effort_shortcut_list(help: &ModeInfo, max_len: usize) -> LinePart {
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.len() == 0); let select_pane_shortcut = select_pane_shortcut(help.keybinds.is_empty());
if line_part.len + select_pane_shortcut.len <= max_len { 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,);
@ -178,5 +178,5 @@ pub fn keybinds(help: &ModeInfo, max_width: usize) -> LinePart {
if shortened_shortcut_list.len <= max_width { if shortened_shortcut_list.len <= max_width {
return shortened_shortcut_list; return shortened_shortcut_list;
} }
return best_effort_shortcut_list(help, max_width); best_effort_shortcut_list(help, max_width)
} }

View file

@ -130,7 +130,7 @@ fn add_next_tabs_msg(
} }
fn tab_line_prefix() -> LinePart { fn tab_line_prefix() -> LinePart {
let prefix_text = format!(" Zellij "); let prefix_text = " Zellij ".to_string();
let prefix_text_len = prefix_text.chars().count(); let prefix_text_len = prefix_text.chars().count();
let prefix_styled_text = Style::new().fg(WHITE).on(GRAY).bold().paint(prefix_text); let prefix_styled_text = Style::new().fg(WHITE).on(GRAY).bold().paint(prefix_text);
LinePart { LinePart {