wip: colors adjustments

This commit is contained in:
denis 2021-04-24 11:25:09 +03:00
parent fef466c74b
commit c44de89350
5 changed files with 91 additions and 69 deletions

View file

@ -140,7 +140,7 @@ fn color_elements(palette: Palette) -> ColoredElements {
.fg(RGB(palette.bg.0, palette.bg.1, palette.bg.2))
.on(RGB(palette.green.0, palette.green.1, palette.green.2)),
Style::new()
.fg(RGB(palette.fg.0, palette.fg.1, palette.fg.2))
.fg(RGB(palette.black.0, palette.black.1, palette.black.2))
.on(RGB(palette.green.0, palette.green.1, palette.green.2))
.bold(),
Style::new()
@ -149,16 +149,16 @@ fn color_elements(palette: Palette) -> ColoredElements {
.on(RGB(palette.green.0, palette.green.1, palette.green.2))
.bold(),
Style::new()
.fg(RGB(palette.fg.0, palette.fg.1, palette.fg.2))
.fg(RGB(palette.black.0, palette.black.1, palette.black.2))
.on(RGB(palette.green.0, palette.green.1, palette.green.2))
.bold(),
Style::new()
.fg(RGB(palette.fg.0, palette.fg.1, palette.fg.2))
.fg(RGB(palette.black.0, palette.black.1, palette.black.2))
.on(RGB(palette.green.0, palette.green.1, palette.green.2))
.bold(),
Style::new()
.fg(RGB(palette.fg.0, palette.fg.1, palette.fg.2))
.on(RGB(palette.green.0, palette.green.1, palette.green.2))
.fg(RGB(palette.green.0, palette.green.1, palette.green.2))
.on(RGB(palette.bg.0, palette.bg.1, palette.bg.2))
.bold(),
Style::new()
.fg(RGB(palette.bg.0, palette.bg.1, palette.bg.2))
@ -179,7 +179,7 @@ fn color_elements(palette: Palette) -> ColoredElements {
.on(RGB(palette.fg.0, palette.fg.1, palette.fg.2))
.bold(),
Style::new()
.fg(RGB(palette.bg.0, palette.bg.1, palette.bg.2))
.fg(RGB(palette.black.0, palette.black.1, palette.black.2))
.on(RGB(palette.fg.0, palette.fg.1, palette.fg.2))
.bold(),
Style::new()
@ -218,11 +218,11 @@ fn color_elements(palette: Palette) -> ColoredElements {
.fg(RGB(palette.fg.0, palette.fg.1, palette.fg.2))
.on(RGB(palette.bg.0, palette.bg.1, palette.bg.2)),
Style::new()
.fg(RGB(palette.bg.0, palette.bg.1, palette.bg.2))
.on(RGB(palette.fg.0, palette.fg.1, palette.fg.2))
.fg(RGB(palette.white.0, palette.white.1, palette.white.2))
.on(RGB(palette.bg.0, palette.bg.1, palette.bg.2))
.bold(),
Style::new()
.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.bg.0, palette.bg.1, palette.bg.2)),
),
PaletteSource::Xresources => ColoredElements::new(
@ -247,8 +247,8 @@ fn color_elements(palette: Palette) -> ColoredElements {
.on(RGB(palette.green.0, palette.green.1, palette.green.2))
.bold(),
Style::new()
.fg(RGB(palette.fg.0, palette.fg.1, palette.fg.2))
.on(RGB(palette.green.0, palette.green.1, palette.green.2))
.fg(RGB(palette.green.0, palette.green.1, palette.green.2))
.on(RGB(palette.bg.0, palette.bg.1, palette.bg.2))
.bold(),
Style::new()
.fg(RGB(palette.bg.0, palette.bg.1, palette.bg.2))

View file

@ -1,8 +1,11 @@
// use colored::*;
use ansi_term::{ANSIStrings, Color::RGB, Style};
use zellij_tile::{data::Theme, prelude::*};
use zellij_tile::prelude::*;
use crate::colors::{GREEN, ORANGE, WHITE};
use crate::{
colors::{GREEN, ORANGE, WHITE},
ColoredElements,
};
use crate::{LinePart, MORE_MSG};
fn full_length_shortcut(
@ -13,27 +16,22 @@ fn full_length_shortcut(
) -> LinePart {
let separator = if is_first_shortcut { " " } else { " / " };
let separator = Style::new()
.on(RGB(palette.black.0, palette.black.1, palette.black.2))
.fg(RGB(palette.white.0, palette.white.1, palette.white.2))
.fg(RGB(palette.fg.0, palette.fg.1, palette.fg.2))
.paint(separator);
let shortcut_len = letter.chars().count() + 3; // 2 for <>'s around shortcut, 1 for the space
let shortcut_left_separator = Style::new()
.on(RGB(palette.black.0, palette.black.1, palette.black.2))
.fg(RGB(palette.white.0, palette.white.1, palette.white.2))
.fg(RGB(palette.fg.0, palette.fg.1, palette.fg.2))
.paint("<");
let shortcut = Style::new()
.on(RGB(palette.bg.0, palette.bg.1, palette.bg.2))
.fg(ORANGE)
.fg(RGB(palette.green.0, palette.green.1, palette.green.2))
.bold()
.paint(letter);
let shortcut_right_separator = Style::new()
.on(RGB(palette.black.0, palette.black.1, palette.black.2))
.fg(RGB(palette.white.0, palette.white.1, palette.white.2))
.fg(RGB(palette.fg.0, palette.fg.1, palette.fg.2))
.paint("> ");
let description_len = description.chars().count();
let description = Style::new()
.on(RGB(palette.black.0, palette.black.1, palette.black.2))
.fg(RGB(palette.white.0, palette.white.1, palette.white.2))
.fg(RGB(palette.fg.0, palette.fg.1, palette.fg.2))
.bold()
.paint(description);
let len = shortcut_len + description_len + separator.chars().count();
@ -60,28 +58,23 @@ fn first_word_shortcut(
) -> LinePart {
let separator = if is_first_shortcut { " " } else { " / " };
let separator = Style::new()
.on(RGB(palette.black.0, palette.black.1, palette.black.2))
.fg(RGB(palette.white.0, palette.white.1, palette.white.2))
.fg(RGB(palette.fg.0, palette.fg.1, palette.fg.2))
.paint(separator);
let shortcut_len = letter.chars().count() + 3; // 2 for <>'s around shortcut, 1 for the space
let shortcut_left_separator = Style::new()
.on(RGB(palette.black.0, palette.black.1, palette.black.2))
.fg(RGB(palette.white.0, palette.white.1, palette.white.2))
.fg(RGB(palette.fg.0, palette.fg.1, palette.fg.2))
.paint("<");
let shortcut = Style::new()
.on(RGB(palette.bg.0, palette.bg.1, palette.bg.2))
.fg(RGB(palette.green.0, palette.green.1, palette.green.2))
.bold()
.paint(letter);
let shortcut_right_separator = Style::new()
.on(RGB(palette.black.0, palette.black.1, palette.black.2))
.fg(RGB(palette.white.0, palette.white.1, palette.white.2))
.fg(RGB(palette.fg.0, palette.fg.1, palette.fg.2))
.paint("> ");
let description_first_word = description.split(' ').next().unwrap_or("");
let description_first_word_length = description_first_word.chars().count();
let description_first_word = Style::new()
.on(RGB(palette.black.0, palette.black.1, palette.black.2))
.fg(RGB(palette.white.0, palette.white.1, palette.white.2))
.fg(RGB(palette.fg.0, palette.fg.1, palette.fg.2))
.bold()
.paint(description_first_word);
let len = shortcut_len + description_first_word_length + separator.chars().count();
@ -99,7 +92,7 @@ fn first_word_shortcut(
len,
}
}
fn quicknav_full() -> LinePart {
fn quicknav_full(palette: Palette) -> LinePart {
let text_first_part = " Tip: ";
let alt = "Alt";
let text_second_part = " + ";
@ -126,15 +119,30 @@ fn quicknav_full() -> LinePart {
part: format!(
"{}{}{}{}{}{}{}{}{}{}{}",
text_first_part,
Style::new().fg(ORANGE).bold().paint(alt),
Style::new()
.fg(RGB(palette.red.0, palette.red.1, palette.red.2))
.bold()
.paint(alt),
text_second_part,
Style::new().fg(GREEN).bold().paint(new_pane_shortcut),
Style::new()
.fg(RGB(palette.green.0, palette.green.1, palette.green.2))
.bold()
.paint(new_pane_shortcut),
text_third_part,
Style::new().fg(ORANGE).bold().paint(second_alt),
Style::new()
.fg(RGB(palette.red.0, palette.red.1, palette.red.2))
.bold()
.paint(second_alt),
text_fourth_part,
Style::new().fg(GREEN).bold().paint(brackets_navigation),
Style::new()
.fg(RGB(palette.green.0, palette.green.1, palette.green.2))
.bold()
.paint(brackets_navigation),
text_fifth_part,
Style::new().fg(GREEN).bold().paint(hjkl_navigation),
Style::new()
.fg(RGB(palette.green.0, palette.green.1, palette.green.2))
.bold()
.paint(hjkl_navigation),
text_sixths_part,
),
len,
@ -220,7 +228,7 @@ fn locked_interface_indication(palette: Palette) -> LinePart {
let locked_text = " -- INTERFACE LOCKED -- ";
let locked_text_len = locked_text.chars().count();
let locked_styled_text = Style::new()
.fg(RGB(palette.white.0, palette.white.1, palette.white.2))
.fg(RGB(palette.fg.0, palette.fg.1, palette.fg.2))
.bold()
.paint(locked_text);
LinePart {
@ -234,27 +242,22 @@ fn select_pane_shortcut(is_first_shortcut: bool, palette: Palette) -> LinePart {
let description = "Select pane";
let separator = if is_first_shortcut { " " } else { " / " };
let separator = Style::new()
.on(RGB(palette.black.0, palette.black.1, palette.black.2))
.fg(RGB(palette.white.0, palette.white.1, palette.white.2))
.fg(RGB(palette.fg.0, palette.fg.1, palette.fg.2))
.paint(separator);
let shortcut_len = shortcut.chars().count() + 3; // 2 for <>'s around shortcut, 1 for the space
let shortcut_left_separator = Style::new()
.on(RGB(palette.black.0, palette.black.1, palette.black.2))
.fg(RGB(palette.white.0, palette.white.1, palette.white.2))
.fg(RGB(palette.fg.0, palette.fg.1, palette.fg.2))
.paint("<");
let shortcut = Style::new()
.on(RGB(palette.black.0, palette.black.1, palette.black.2))
.fg(ORANGE)
.fg(RGB(palette.red.0, palette.red.1, palette.red.2))
.bold()
.paint(shortcut);
let shortcut_right_separator = Style::new()
.on(RGB(palette.black.0, palette.black.1, palette.black.2))
.fg(RGB(palette.white.0, palette.white.1, palette.white.2))
.fg(RGB(palette.fg.0, palette.fg.1, palette.fg.2))
.paint("> ");
let description_len = description.chars().count();
let description = Style::new()
.on(RGB(palette.black.0, palette.black.1, palette.black.2))
.fg(RGB(palette.white.0, palette.white.1, palette.white.2))
.fg(RGB(palette.fg.0, palette.fg.1, palette.fg.2))
.bold()
.paint(description);
let len = shortcut_len + description_len + separator.chars().count();
@ -275,7 +278,7 @@ fn select_pane_shortcut(is_first_shortcut: bool, palette: Palette) -> LinePart {
fn full_shortcut_list(help: &ModeInfo) -> LinePart {
match help.mode {
InputMode::Normal => quicknav_full(),
InputMode::Normal => quicknav_full(help.palette),
InputMode::Locked => locked_interface_indication(help.palette),
_ => {
let mut line_part = LinePart::default();

View file

@ -1,7 +1,8 @@
use crate::colors::{BLACK, GRAY, ORANGE, WHITE};
use ansi_term::{ANSIStrings, Style};
use ansi_term::{ANSIStrings, Color::RGB, Style};
use crate::{LinePart, ARROW_SEPARATOR};
use zellij_tile::data::Palette;
fn get_current_title_len(current_title: &[LinePart]) -> usize {
current_title
@ -47,7 +48,7 @@ fn populate_tabs_in_tab_line(
}
}
fn left_more_message(tab_count_to_the_left: usize) -> LinePart {
fn left_more_message(tab_count_to_the_left: usize, palette: Palette) -> LinePart {
if tab_count_to_the_left == 0 {
return LinePart {
part: String::new(),
@ -62,7 +63,11 @@ fn left_more_message(tab_count_to_the_left: usize) -> LinePart {
// 238
let more_text_len = more_text.chars().count() + 2; // 2 for the arrows
let left_separator = Style::new().fg(GRAY).on(ORANGE).paint(ARROW_SEPARATOR);
let more_styled_text = Style::new().fg(BLACK).on(ORANGE).bold().paint(more_text);
let more_styled_text = Style::new()
.fg(RGB(palette.fg.0, palette.fg.1, palette.fg.2))
.on(ORANGE)
.bold()
.paint(more_text);
let right_separator = Style::new().fg(ORANGE).on(GRAY).paint(ARROW_SEPARATOR);
let more_styled_text = format!(
"{}",
@ -74,7 +79,7 @@ fn left_more_message(tab_count_to_the_left: usize) -> LinePart {
}
}
fn right_more_message(tab_count_to_the_right: usize) -> LinePart {
fn right_more_message(tab_count_to_the_right: usize, palette: Palette) -> LinePart {
if tab_count_to_the_right == 0 {
return LinePart {
part: String::new(),
@ -88,7 +93,11 @@ fn right_more_message(tab_count_to_the_right: usize) -> LinePart {
};
let more_text_len = more_text.chars().count() + 1; // 2 for the arrow
let left_separator = Style::new().fg(GRAY).on(ORANGE).paint(ARROW_SEPARATOR);
let more_styled_text = Style::new().fg(BLACK).on(ORANGE).bold().paint(more_text);
let more_styled_text = Style::new()
.fg(RGB(palette.fg.0, palette.fg.1, palette.fg.2))
.on(ORANGE)
.bold()
.paint(more_text);
let right_separator = Style::new().fg(ORANGE).on(GRAY).paint(ARROW_SEPARATOR);
let more_styled_text = format!(
"{}",
@ -105,13 +114,15 @@ fn add_previous_tabs_msg(
tabs_to_render: &mut Vec<LinePart>,
title_bar: &mut Vec<LinePart>,
cols: usize,
palette: Palette,
) {
while get_current_title_len(&tabs_to_render) + left_more_message(tabs_before_active.len()).len
while get_current_title_len(&tabs_to_render)
+ left_more_message(tabs_before_active.len(), palette).len
>= cols
{
tabs_before_active.push(tabs_to_render.remove(0));
}
let left_more_message = left_more_message(tabs_before_active.len());
let left_more_message = left_more_message(tabs_before_active.len(), palette);
title_bar.push(left_more_message);
}
@ -119,20 +130,26 @@ fn add_next_tabs_msg(
tabs_after_active: &mut Vec<LinePart>,
title_bar: &mut Vec<LinePart>,
cols: usize,
palette: Palette,
) {
while get_current_title_len(&title_bar) + right_more_message(tabs_after_active.len()).len
while get_current_title_len(&title_bar)
+ right_more_message(tabs_after_active.len(), palette).len
>= cols
{
tabs_after_active.insert(0, title_bar.pop().unwrap());
}
let right_more_message = right_more_message(tabs_after_active.len());
let right_more_message = right_more_message(tabs_after_active.len(), palette);
title_bar.push(right_more_message);
}
fn tab_line_prefix() -> LinePart {
fn tab_line_prefix(palette: Palette) -> LinePart {
let prefix_text = " Zellij ".to_string();
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(RGB(palette.fg.0, palette.fg.1, palette.fg.2))
.on(RGB(palette.bg.0, palette.bg.1, palette.bg.2))
.bold()
.paint(prefix_text);
LinePart {
part: format!("{}", prefix_styled_text),
len: prefix_text_len,
@ -143,6 +160,7 @@ pub fn tab_line(
mut all_tabs: Vec<LinePart>,
active_tab_index: usize,
cols: usize,
palette: Palette,
) -> Vec<LinePart> {
let mut tabs_to_render: Vec<LinePart> = vec![];
let mut tabs_after_active = all_tabs.split_off(active_tab_index);
@ -154,7 +172,7 @@ pub fn tab_line(
};
tabs_to_render.push(active_tab);
let prefix = tab_line_prefix();
let prefix = tab_line_prefix(palette);
populate_tabs_in_tab_line(
&mut tabs_before_active,
&mut tabs_after_active,
@ -169,11 +187,12 @@ pub fn tab_line(
&mut tabs_to_render,
&mut tab_line,
cols - prefix.len,
palette,
);
}
tab_line.append(&mut tabs_to_render);
if !tabs_after_active.is_empty() {
add_next_tabs_msg(&mut tabs_after_active, &mut tab_line, cols - prefix.len);
add_next_tabs_msg(&mut tabs_after_active, &mut tab_line, cols - prefix.len, palette);
}
tab_line.insert(0, prefix);
tab_line

View file

@ -68,7 +68,7 @@ impl ZellijPlugin for State {
let tab = tab_style(tabname, t.active, t.position, self.mode_info.palette);
all_tabs.push(tab);
}
let tab_line = tab_line(all_tabs, active_tab_index, cols);
let tab_line = tab_line(all_tabs, active_tab_index, cols, self.mode_info.palette);
let mut s = String::new();
for bar_part in tab_line {
s = format!("{}{}", s, bar_part.part);
@ -76,9 +76,9 @@ impl ZellijPlugin for State {
println!(
"{}\u{1b}[48;2;{};{};{}m\u{1b}[0K",
s,
self.mode_info.palette.fg.0,
self.mode_info.palette.fg.1,
self.mode_info.palette.fg.2
self.mode_info.palette.bg.0,
self.mode_info.palette.bg.1,
self.mode_info.palette.bg.2
);
}
}

View file

@ -5,12 +5,12 @@ use zellij_tile::data::Palette;
pub fn active_tab(text: String, palette: Palette) -> LinePart {
let left_separator = Style::new()
.fg(RGB(palette.black.0, palette.black.1, palette.black.2))
.fg(RGB(palette.fg.0, palette.fg.1, palette.fg.2))
.on(RGB(palette.green.0, palette.green.1, palette.green.2))
.paint(ARROW_SEPARATOR);
let tab_text_len = text.chars().count() + 4; // 2 for left and right separators, 2 for the text padding
let tab_styled_text = Style::new()
.fg(RGB(palette.black.0, palette.black.1, palette.black.2))
.fg(RGB(palette.fg.0, palette.fg.1, palette.fg.2))
.on(RGB(palette.green.0, palette.green.1, palette.green.2))
.bold()
.paint(format!(" {} ", text));