wip: looks cleaner

This commit is contained in:
denis 2021-04-09 14:56:04 +03:00
parent 748a7ffa6e
commit b9f3e35a4a
3 changed files with 41 additions and 57 deletions

View File

@ -63,51 +63,37 @@ impl CtrlKeyShortcut {
} }
} }
fn get_bg(palette: Palette) -> (u8, u8, u8) {
match palette.theme {
Theme::Dark => palette.white,
Theme::Light => palette.fg,
}
}
fn get_fg(palette: Palette) -> (u8, u8, u8) {
match palette.theme {
Theme::Dark => palette.black,
Theme::Light => palette.bg,
}
}
fn unselected_mode_shortcut(letter: char, text: &str, palette: Palette) -> LinePart { fn unselected_mode_shortcut(letter: char, text: &str, palette: Palette) -> LinePart {
let prefix_separator = Style::new() let prefix_separator = Style::new()
.fg(RGB(get_fg(palette).0, get_fg(palette).1, get_fg(palette).2)) .fg(RGB(palette.bg.0, palette.bg.1, palette.bg.2))
.on(RGB(get_bg(palette).0, get_bg(palette).1, get_bg(palette).2)) .on(RGB(palette.fg.0, palette.fg.1, palette.fg.2))
.paint(ARROW_SEPARATOR); .paint(ARROW_SEPARATOR);
let char_left_separator = Style::new() let char_left_separator = Style::new()
.bold() .bold()
.fg(RGB(get_fg(palette).0, get_fg(palette).1, get_fg(palette).2)) .fg(RGB(palette.bg.0, palette.bg.1, palette.bg.2))
.on(RGB(get_bg(palette).0, get_bg(palette).1, get_bg(palette).2)) .on(RGB(palette.fg.0, palette.fg.1, palette.fg.2))
.bold() .bold()
.paint(" <"); .paint(" <");
let char_shortcut = Style::new() let char_shortcut = Style::new()
.bold() .bold()
.fg(RGB(palette.red.0, palette.red.1, palette.red.2)) .fg(RGB(palette.red.0, palette.red.1, palette.red.2))
.on(RGB(get_bg(palette).0, get_bg(palette).1, get_bg(palette).2)) .on(RGB(palette.fg.0, palette.fg.1, palette.fg.2))
.bold() .bold()
.paint(letter.to_string()); .paint(letter.to_string());
let char_right_separator = Style::new() let char_right_separator = Style::new()
.bold() .bold()
.fg(RGB(get_fg(palette).0, get_fg(palette).1, get_fg(palette).2)) .fg(RGB(palette.bg.0, palette.bg.1, palette.bg.2))
.on(RGB(get_bg(palette).0, get_bg(palette).1, get_bg(palette).2)) .on(RGB(palette.fg.0, palette.fg.1, palette.fg.2))
.bold() .bold()
.paint(">"); .paint(">");
let styled_text = Style::new() let styled_text = Style::new()
.fg(RGB(get_fg(palette).0, get_fg(palette).1, get_fg(palette).2)) .fg(RGB(palette.bg.0, palette.bg.1, palette.bg.2))
.on(RGB(get_bg(palette).0, get_bg(palette).1, get_bg(palette).2)) .on(RGB(palette.fg.0, palette.fg.1, palette.fg.2))
.bold() .bold()
.paint(format!("{} ", text)); .paint(format!("{} ", text));
let suffix_separator = Style::new() let suffix_separator = Style::new()
.fg(RGB(get_fg(palette).0, get_fg(palette).1, get_fg(palette).2)) .fg(RGB(palette.fg.0, palette.fg.1, palette.fg.2))
.on(RGB(get_bg(palette).0, get_bg(palette).1, get_bg(palette).2)) .on(RGB(palette.bg.0, palette.bg.1, palette.bg.2))
.paint(ARROW_SEPARATOR); .paint(ARROW_SEPARATOR);
LinePart { LinePart {
part: ANSIStrings(&[ part: ANSIStrings(&[
@ -125,12 +111,11 @@ fn unselected_mode_shortcut(letter: char, text: &str, palette: Palette) -> LineP
fn selected_mode_shortcut(letter: char, text: &str, palette: Palette) -> LinePart { fn selected_mode_shortcut(letter: char, text: &str, palette: Palette) -> LinePart {
let prefix_separator = Style::new() let prefix_separator = Style::new()
.fg(RGB(get_fg(palette).0, get_fg(palette).1, get_fg(palette).2)) .fg(RGB(palette.bg.0, palette.bg.1, palette.bg.2))
.on(RGB(get_bg(palette).0, get_bg(palette).1, get_bg(palette).2)) .on(RGB(palette.green.0, palette.green.1, palette.green.2))
.paint(ARROW_SEPARATOR); .paint(ARROW_SEPARATOR);
let char_left_separator = Style::new() let char_left_separator = Style::new()
.bold() .fg(RGB(palette.fg.0, palette.fg.1, palette.fg.2))
.fg(RGB(palette.bg.0, palette.bg.1, palette.bg.2))
.on(RGB(palette.green.0, palette.green.1, palette.green.2)) .on(RGB(palette.green.0, palette.green.1, palette.green.2))
.bold() .bold()
.paint(format!(" <")); .paint(format!(" <"));
@ -141,19 +126,18 @@ fn selected_mode_shortcut(letter: char, text: &str, palette: Palette) -> LinePar
.bold() .bold()
.paint(format!("{}", letter)); .paint(format!("{}", letter));
let char_right_separator = Style::new() let char_right_separator = Style::new()
.bold() .fg(RGB(palette.fg.0, palette.fg.1, palette.fg.2))
.fg(RGB(palette.bg.0, palette.bg.1, palette.bg.2))
.on(RGB(palette.green.0, palette.green.1, palette.green.2)) .on(RGB(palette.green.0, palette.green.1, palette.green.2))
.bold() .bold()
.paint(format!(">")); .paint(format!(">"));
let styled_text = Style::new() let styled_text = Style::new()
.fg(RGB(get_fg(palette).0, get_fg(palette).1, get_fg(palette).2)) .fg(RGB(palette.fg.0, palette.fg.1, palette.fg.2))
.on(RGB(palette.green.0, palette.green.1, palette.green.2)) .on(RGB(palette.green.0, palette.green.1, palette.green.2))
.bold() .bold()
.paint(format!("{} ", text)); .paint(format!("{} ", text));
let suffix_separator = Style::new() let suffix_separator = Style::new()
.fg(RGB(get_fg(palette).0, get_fg(palette).1, get_fg(palette).2)) .fg(RGB(palette.green.0, palette.green.1, palette.green.2))
.on(RGB(palette.green.0, palette.green.1, palette.green.2)) .on(RGB(palette.bg.0, palette.bg.1, palette.bg.2))
.paint(ARROW_SEPARATOR); .paint(ARROW_SEPARATOR);
LinePart { LinePart {
part: ANSIStrings(&[ part: ANSIStrings(&[
@ -171,17 +155,17 @@ fn selected_mode_shortcut(letter: char, text: &str, palette: Palette) -> LinePar
fn disabled_mode_shortcut(text: &str, palette: Palette) -> LinePart { fn disabled_mode_shortcut(text: &str, palette: Palette) -> LinePart {
let prefix_separator = Style::new() let prefix_separator = Style::new()
.fg(RGB(get_fg(palette).0, get_fg(palette).1, get_fg(palette).2)) .fg(RGB(palette.bg.0, palette.bg.1, palette.bg.2))
.on(RGB(get_bg(palette).0, get_bg(palette).1, get_bg(palette).2)) .on(RGB(palette.fg.0, palette.fg.1, palette.fg.2))
.paint(ARROW_SEPARATOR); .paint(ARROW_SEPARATOR);
let styled_text = Style::new() let styled_text = Style::new()
.fg(RGB(get_fg(palette).0, get_fg(palette).1, get_fg(palette).2)) .fg(RGB(palette.bg.0, palette.bg.1, palette.bg.2))
.on(RGB(get_bg(palette).0, get_bg(palette).1, get_bg(palette).2)) .on(RGB(palette.fg.0, palette.fg.1, palette.fg.2))
.dimmed() .dimmed()
.paint(format!("{} ", text)); .paint(format!("{} ", text));
let suffix_separator = Style::new() let suffix_separator = Style::new()
.fg(RGB(get_fg(palette).0, get_fg(palette).1, get_fg(palette).2)) .fg(RGB(palette.bg.0, palette.bg.1, palette.bg.2))
.on(RGB(get_bg(palette).0, get_bg(palette).1, get_bg(palette).2)) .on(RGB(palette.fg.0, palette.fg.1, palette.fg.2))
.paint(ARROW_SEPARATOR); .paint(ARROW_SEPARATOR);
LinePart { LinePart {
part: format!("{}{}{}", prefix_separator, styled_text, suffix_separator), part: format!("{}{}{}", prefix_separator, styled_text, suffix_separator),
@ -193,7 +177,7 @@ fn selected_mode_shortcut_single_letter(letter: char, palette: Palette) -> LineP
let char_shortcut_text = format!(" {} ", letter); let char_shortcut_text = format!(" {} ", letter);
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() let prefix_separator = Style::new()
.fg(RGB(get_fg(palette).0, get_fg(palette).1, get_fg(palette).2)) .fg(RGB(palette.fg.0, palette.fg.1, palette.fg.2))
.on(RGB(palette.green.0, palette.green.1, palette.green.2)) .on(RGB(palette.green.0, palette.green.1, palette.green.2))
.paint(ARROW_SEPARATOR); .paint(ARROW_SEPARATOR);
let char_shortcut = Style::new() let char_shortcut = Style::new()
@ -203,8 +187,8 @@ fn selected_mode_shortcut_single_letter(letter: char, palette: Palette) -> LineP
.bold() .bold()
.paint(char_shortcut_text); .paint(char_shortcut_text);
let suffix_separator = Style::new() let suffix_separator = Style::new()
.fg(RGB(get_fg(palette).0, get_fg(palette).1, get_fg(palette).2)) .fg(RGB(palette.bg.0, palette.bg.1, palette.bg.2))
.on(RGB(get_bg(palette).0, get_bg(palette).1, get_bg(palette).2)) .on(RGB(palette.fg.0, palette.fg.1, palette.fg.2))
.paint(ARROW_SEPARATOR); .paint(ARROW_SEPARATOR);
LinePart { LinePart {
part: ANSIStrings(&[prefix_separator, char_shortcut, suffix_separator]).to_string(), part: ANSIStrings(&[prefix_separator, char_shortcut, suffix_separator]).to_string(),
@ -216,18 +200,18 @@ fn unselected_mode_shortcut_single_letter(letter: char, palette: Palette) -> Lin
let char_shortcut_text = format!(" {} ", letter); let char_shortcut_text = format!(" {} ", letter);
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() let prefix_separator = Style::new()
.fg(RGB(get_fg(palette).0, get_fg(palette).1, get_fg(palette).2)) .fg(RGB(palette.bg.0, palette.bg.1, palette.bg.2))
.on(RGB(get_bg(palette).0, get_bg(palette).1, get_bg(palette).2)) .on(RGB(palette.fg.0, palette.fg.1, palette.fg.2))
.paint(ARROW_SEPARATOR); .paint(ARROW_SEPARATOR);
let char_shortcut = Style::new() let char_shortcut = Style::new()
.bold() .bold()
.fg(RGB(palette.red.0, palette.red.1, palette.red.2)) .fg(RGB(palette.red.0, palette.red.1, palette.red.2))
.on(RGB(get_bg(palette).0, get_bg(palette).1, get_bg(palette).2)) .on(RGB(palette.fg.0, palette.fg.1, palette.fg.2))
.bold() .bold()
.paint(char_shortcut_text); .paint(char_shortcut_text);
let suffix_separator = Style::new() let suffix_separator = Style::new()
.fg(RGB(get_fg(palette).0, get_fg(palette).1, get_fg(palette).2)) .fg(RGB(palette.bg.0, palette.bg.1, palette.bg.2))
.on(RGB(get_bg(palette).0, get_bg(palette).1, get_bg(palette).2)) .on(RGB(palette.fg.0, palette.fg.1, palette.fg.2))
.paint(ARROW_SEPARATOR); .paint(ARROW_SEPARATOR);
LinePart { LinePart {
part: ANSIStrings(&[prefix_separator, char_shortcut, suffix_separator]).to_string(), part: ANSIStrings(&[prefix_separator, char_shortcut, suffix_separator]).to_string(),
@ -318,8 +302,8 @@ fn key_indicators(max_len: usize, keys: &[CtrlKeyShortcut], palette: Palette) ->
pub fn superkey(palette: Palette) -> LinePart { pub fn superkey(palette: Palette) -> LinePart {
let prefix_text = " Ctrl + "; let prefix_text = " Ctrl + ";
let prefix = Style::new() let prefix = Style::new()
.fg(RGB(get_fg(palette).0, get_fg(palette).1, get_fg(palette).2)) .fg(RGB(palette.bg.0, palette.bg.1, palette.bg.2))
.on(RGB(get_bg(palette).0, get_bg(palette).1, get_bg(palette).2)) .on(RGB(palette.fg.0, palette.fg.1, palette.fg.2))
.bold() .bold()
.paint(prefix_text); .paint(prefix_text);
LinePart { LinePart {

View File

@ -67,9 +67,9 @@ impl ZellijTile for State {
println!( println!(
"{}\u{1b}[48;2;{};{};{}m\u{1b}[0K", "{}\u{1b}[48;2;{};{};{}m\u{1b}[0K",
first_line, first_line,
self.mode_info.palette.fg.0, self.mode_info.palette.bg.0,
self.mode_info.palette.fg.1, self.mode_info.palette.bg.1,
self.mode_info.palette.fg.2 self.mode_info.palette.bg.2
); );
println!("\u{1b}[m{}\u{1b}[0K", second_line); println!("\u{1b}[m{}\u{1b}[0K", second_line);
} }

View File

@ -74,11 +74,11 @@ impl ZellijTile for State {
s = format!("{}{}", s, bar_part.part); s = format!("{}{}", s, bar_part.part);
} }
println!( println!(
"{}\u{1b}[{};{};{}m\u{1b}[0K", "{}\u{1b}[48;2;{};{};{}m\u{1b}[0K",
s, s,
self.mode_info.palette.bg.0, self.mode_info.palette.fg.0,
self.mode_info.palette.bg.1, self.mode_info.palette.fg.1,
self.mode_info.palette.bg.2 self.mode_info.palette.fg.2
); );
} }
} }