Skip to content

Commit 7b89eff

Browse files
authored
Remap White ANSI color to Default (#625)
Allows the "white" color to have the greatest chance of being a dark, visible color for light terminal themes. A macro is used to remap `White` to `Default` to minimize size of the diff and prevent contributors from needing to be familiar with the `Default` color on top of the 8 standard colors. In other places where `White` was assumed to be the default, `Default` is now used instead, also. For #33 Closes #611
1 parent 3d914aa commit 7b89eff

File tree

3 files changed

+26
-15
lines changed

3 files changed

+26
-15
lines changed

Diff for: src/info/langs/language.rs

+13-2
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,20 @@ pub struct Colors {
88
true_colors: Option<Vec<DynColors>>,
99
}
1010

11+
/// Maps colors to preferred versions. Used to allow contributors to include
12+
/// colors with minimal confusion.
13+
macro_rules! clean_color {
14+
( White ) => {
15+
clean_color!(Default)
16+
};
17+
( $color:ident ) => {
18+
DynColors::Ansi(AnsiColors::$color)
19+
};
20+
}
21+
1122
macro_rules! define_colors {
12-
( [ $($color:ident),+ ] ) => { Colors { basic_colors: vec![$(DynColors::Ansi(AnsiColors::$color)),+], true_colors: None } };
13-
( [ $($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)),+]) } };
23+
( [ $($color:ident),+ ] ) => { Colors { basic_colors: vec![$( clean_color!($color) ),+], true_colors: None } };
24+
( [ $($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)),+]) } };
1425
}
1526

1627
#[derive(PartialEq, EnumString, EnumIter, IntoStaticStr)]

Diff for: src/info/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ impl Info {
335335
languages.push((
336336
"Other".to_string(),
337337
other_perc,
338-
DynColors::Ansi(AnsiColors::White),
338+
DynColors::Ansi(AnsiColors::Default),
339339
));
340340
languages
341341
} else {

Diff for: src/ui/ascii_art.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ impl<'a> Tokens<'a> {
155155
let mut width = end - start;
156156
let mut colored_segment = String::new();
157157
let mut whole_string = String::new();
158-
let mut color = &DynColors::Ansi(AnsiColors::White);
158+
let mut color = &DynColors::Ansi(AnsiColors::Default);
159159

160160
self.truncate(start, end).for_each(|token| {
161161
match token {
@@ -168,7 +168,7 @@ impl<'a> Tokens<'a> {
168168
colored_segment = String::new();
169169
color = colors
170170
.get(col as usize)
171-
.unwrap_or(&DynColors::Ansi(AnsiColors::White));
171+
.unwrap_or(&DynColors::Ansi(AnsiColors::Default));
172172
}
173173
Token::Space => {
174174
width = width.saturating_sub(1);
@@ -266,52 +266,52 @@ mod test {
266266

267267
assert_eq!(
268268
Tokens("").render(&colors_shim, 0, 0, true),
269-
"\u{1b}[37;1m\u{1b}[0m"
269+
"\u{1b}[39;1m\u{1b}[0m"
270270
);
271271

272272
assert_eq!(
273273
Tokens(" ").render(&colors_shim, 0, 0, true),
274-
"\u{1b}[37;1m\u{1b}[0m"
274+
"\u{1b}[39;1m\u{1b}[0m"
275275
);
276276

277277
assert_eq!(
278278
Tokens(" ").render(&colors_shim, 0, 5, true),
279-
"\u{1b}[37;1m \u{1b}[0m"
279+
"\u{1b}[39;1m \u{1b}[0m"
280280
);
281281

282282
assert_eq!(
283283
Tokens(" ").render(&colors_shim, 1, 5, true),
284-
"\u{1b}[37;1m \u{1b}[0m"
284+
"\u{1b}[39;1m \u{1b}[0m"
285285
);
286286

287287
assert_eq!(
288288
Tokens(" ").render(&colors_shim, 3, 5, true),
289-
"\u{1b}[37;1m \u{1b}[0m"
289+
"\u{1b}[39;1m \u{1b}[0m"
290290
);
291291

292292
assert_eq!(
293293
Tokens(" ").render(&colors_shim, 0, 4, true),
294-
"\u{1b}[37;1m \u{1b}[0m"
294+
"\u{1b}[39;1m \u{1b}[0m"
295295
);
296296

297297
assert_eq!(
298298
Tokens(" ").render(&colors_shim, 0, 3, true),
299-
"\u{1b}[37;1m \u{1b}[0m"
299+
"\u{1b}[39;1m \u{1b}[0m"
300300
);
301301

302302
assert_eq!(
303303
Tokens(" {1} {5} {9} a").render(&colors_shim, 4, 10, true),
304-
"\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 "
304+
"\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 "
305305
);
306306

307307
// Tests for bold disabled
308308
assert_eq!(
309309
Tokens(" ").render(&colors_shim, 0, 0, false),
310-
"\u{1b}[37m\u{1b}[0m"
310+
"\u{1b}[39m\u{1b}[0m"
311311
);
312312
assert_eq!(
313313
Tokens(" ").render(&colors_shim, 0, 5, false),
314-
"\u{1b}[37m \u{1b}[0m"
314+
"\u{1b}[39m \u{1b}[0m"
315315
);
316316
}
317317

0 commit comments

Comments
 (0)