use ansi_term::{
unstyled_len, ANSIString, ANSIStrings,
Color::{Fixed, RGB},
Style,
};
use zellij_tile::prelude::actions::Action;
use zellij_tile::prelude::*;
use zellij_tile_utils::palette_match;
use crate::{
action_key, action_key_group, style_key_with_modifier,
tip::{data::TIPS, TipFn},
LinePart, MORE_MSG, TO_NORMAL,
};
fn full_length_shortcut(
is_first_shortcut: bool,
key: Vec<Key>,
action: &str,
palette: Palette,
) -> LinePart {
if key.is_empty() {
return LinePart::default();
}
let text_color = palette_match!(match palette.theme_hue {
ThemeHue::Dark => palette.white,
ThemeHue::Light => palette.black,
});
let separator = if is_first_shortcut { " " } else { " / " };
let mut bits: Vec<ANSIString> = vec![Style::new().fg(text_color).paint(separator)];
bits.extend(style_key_with_modifier(&key, &palette));
bits.push(
Style::new()
.fg(text_color)
.bold()
.paint(format!(" {}", action)),
);
let part = ANSIStrings(&bits);
LinePart {
part: part.to_string(),
len: unstyled_len(&part),
}
}
fn locked_interface_indication(palette: Palette) -> LinePart {
let locked_text = " -- INTERFACE LOCKED -- ";
let locked_text_len = locked_text.chars().count();
let text_color = palette_match!(match palette.theme_hue {
ThemeHue::Dark => palette.white,
ThemeHue::Light => palette.black,
});
let locked_styled_text = Style::new().fg(text_color).bold().paint(locked_text);
LinePart {
part: locked_styled_text.to_string(),
len: locked_text_len,
}
}
fn add_shortcut(help: &ModeInfo, linepart: &LinePart, text: &str, keys: Vec<Key>) -> LinePart {
let shortcut = if linepart.len == 0 {
full_length_shortcut(true, keys, text, help.style.colors)
} else {
full_length_shortcut(false, keys, text, help.style.colors)
};
let mut new_linepart = LinePart::default();
new_linepart.len += linepart.len + shortcut.len;
new_linepart.part = format!("{}{}", linepart.part, shortcut);
new_linepart
}
fn full_shortcut_list_nonstandard_mode(help: &ModeInfo) -> LinePart {
let mut line_part = LinePart::default();
let keys_and_hints = get_keys_and_hints(help);
for (long,