Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Default color instead of White #625

Merged
merged 1 commit into from
Mar 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions src/info/langs/language.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,20 @@ pub struct Colors {
true_colors: Option<Vec<DynColors>>,
}

/// Maps colors to preferred versions. Used to allow contributors to include
/// colors with minimal confusion.
macro_rules! clean_color {
( White ) => {
clean_color!(Default)
};
( $color:ident ) => {
DynColors::Ansi(AnsiColors::$color)
};
}

macro_rules! define_colors {
( [ $($color:ident),+ ] ) => { Colors { basic_colors: vec![$(DynColors::Ansi(AnsiColors::$color)),+], true_colors: None } };
( [ $($bc:ident),+ ] : [ $($c:ident($r:expr, $g:expr, $b:expr)),+ ] ) => { Colors { basic_colors: vec![$(DynColors::Ansi(AnsiColors::$bc)),+], true_colors: Some(vec![$(DynColors::$c($r, $g, $b)),+]) } };
( [ $($color:ident),+ ] ) => { Colors { basic_colors: vec![$( clean_color!($color) ),+], true_colors: None } };
( [ $($bc:ident),+ ] : [ $($c:ident($r:expr, $g:expr, $b:expr)),+ ] ) => { Colors { basic_colors: vec![$(clean_color!($bc)),+], true_colors: Some(vec![$(DynColors::$c($r, $g, $b)),+]) } };
}

#[derive(PartialEq, EnumString, EnumIter, IntoStaticStr)]
Expand Down
2 changes: 1 addition & 1 deletion src/info/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ impl Info {
languages.push((
"Other".to_string(),
other_perc,
DynColors::Ansi(AnsiColors::White),
DynColors::Ansi(AnsiColors::Default),
spenserblack marked this conversation as resolved.
Show resolved Hide resolved
));
languages
} else {
Expand Down
24 changes: 12 additions & 12 deletions src/ui/ascii_art.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ impl<'a> Tokens<'a> {
let mut width = end - start;
let mut colored_segment = String::new();
let mut whole_string = String::new();
let mut color = &DynColors::Ansi(AnsiColors::White);
let mut color = &DynColors::Ansi(AnsiColors::Default);

self.truncate(start, end).for_each(|token| {
match token {
Expand All @@ -168,7 +168,7 @@ impl<'a> Tokens<'a> {
colored_segment = String::new();
color = colors
.get(col as usize)
.unwrap_or(&DynColors::Ansi(AnsiColors::White));
.unwrap_or(&DynColors::Ansi(AnsiColors::Default));
}
Token::Space => {
width = width.saturating_sub(1);
Expand Down Expand Up @@ -266,52 +266,52 @@ mod test {

assert_eq!(
Tokens("").render(&colors_shim, 0, 0, true),
"\u{1b}[37;1m\u{1b}[0m"
"\u{1b}[39;1m\u{1b}[0m"
);

assert_eq!(
Tokens(" ").render(&colors_shim, 0, 0, true),
"\u{1b}[37;1m\u{1b}[0m"
"\u{1b}[39;1m\u{1b}[0m"
);

assert_eq!(
Tokens(" ").render(&colors_shim, 0, 5, true),
"\u{1b}[37;1m \u{1b}[0m"
"\u{1b}[39;1m \u{1b}[0m"
);

assert_eq!(
Tokens(" ").render(&colors_shim, 1, 5, true),
"\u{1b}[37;1m \u{1b}[0m"
"\u{1b}[39;1m \u{1b}[0m"
);

assert_eq!(
Tokens(" ").render(&colors_shim, 3, 5, true),
"\u{1b}[37;1m \u{1b}[0m"
"\u{1b}[39;1m \u{1b}[0m"
);

assert_eq!(
Tokens(" ").render(&colors_shim, 0, 4, true),
"\u{1b}[37;1m \u{1b}[0m"
"\u{1b}[39;1m \u{1b}[0m"
);

assert_eq!(
Tokens(" ").render(&colors_shim, 0, 3, true),
"\u{1b}[37;1m \u{1b}[0m"
"\u{1b}[39;1m \u{1b}[0m"
);

assert_eq!(
Tokens(" {1} {5} {9} a").render(&colors_shim, 4, 10, true),
"\u{1b}[37;1m\u{1b}[0m\u{1b}[37;1m\u{1b}[0m\u{1b}[37;1m \u{1b}[0m\u{1b}[37;1m a\u{1b}[0m "
"\u{1b}[39;1m\u{1b}[0m\u{1b}[39;1m\u{1b}[0m\u{1b}[39;1m \u{1b}[0m\u{1b}[39;1m a\u{1b}[0m "
);

// Tests for bold disabled
assert_eq!(
Tokens(" ").render(&colors_shim, 0, 0, false),
"\u{1b}[37m\u{1b}[0m"
"\u{1b}[39m\u{1b}[0m"
);
assert_eq!(
Tokens(" ").render(&colors_shim, 0, 5, false),
"\u{1b}[37m \u{1b}[0m"
"\u{1b}[39m \u{1b}[0m"
);
}

Expand Down