summaryrefslogtreecommitdiffstats
path: root/src/printer.rs
diff options
context:
space:
mode:
authorMitchell Kember <mk12360@gmail.com>2020-11-29 17:16:54 -0500
committerDavid Peter <sharkdp@users.noreply.github.com>2020-12-21 17:05:10 +0100
commit3099f51ba7a19596f084699eeb1b69305a88b9e4 (patch)
tree4c74954c375235470226797ae785584acd2a47bc /src/printer.rs
parent19e7763f3577645bfe34d09e1c832d2bc713d5a9 (diff)
Add ansi theme to replace ansi-light and ansi-dark
This combines ansi-light and ansi-dark into a single theme that works with both light and dark backgrounds. Instead of specifying white/black, the ansi theme uses the terminal's default foreground/background color by setting alpha=01, i.e. #00000001. This is in addition to the alpha=00 encoding where red contains an ANSI color palette number. Now, `--theme ansi-light` and `--theme ansi-dark` will print a deprecation notice and use ansi instead (unless the user has a custom theme named ansi-light or ansi-dark, which would take precedence).
Diffstat (limited to 'src/printer.rs')
-rw-r--r--src/printer.rs28
1 files changed, 17 insertions, 11 deletions
diff --git a/src/printer.rs b/src/printer.rs
index d588083e..a4b143d4 100644
--- a/src/printer.rs
+++ b/src/printer.rs
@@ -448,7 +448,7 @@ impl<'a> Printer for InteractivePrinter<'a> {
if text.len() != text_trimmed.len() {
if let Some(background_color) = background_color {
let mut ansi_style = Style::default();
- ansi_style.background = Some(to_ansi_color(background_color, true_color));
+ ansi_style.background = to_ansi_color(background_color, true_color);
let width = if cursor_total <= cursor_max {
cursor_max - cursor_total + 1
} else {
@@ -589,8 +589,7 @@ impl<'a> Printer for InteractivePrinter<'a> {
if let Some(background_color) = background_color {
let mut ansi_style = Style::default();
- ansi_style.background =
- Some(to_ansi_color(background_color, self.config.true_color));
+ ansi_style.background = to_ansi_color(background_color, self.config.true_color);
write!(
handle,
@@ -624,20 +623,27 @@ impl Colors {
}
fn colored(theme: &Theme, true_color: bool) -> Self {
- let gutter_color = theme
- .settings
- .gutter_foreground
- .map(|c| to_ansi_color(c, true_color))
- .unwrap_or(Fixed(DEFAULT_GUTTER_COLOR));
+ let gutter_style = Style {
+ foreground: match theme.settings.gutter_foreground {
+ // If the theme provides a gutter foreground color, use it.
+ // Note: It might be the special value #00000001, in which case
+ // to_ansi_color returns None and we use an empty Style
+ // (resulting in the terminal's default foreground color).
+ Some(c) => to_ansi_color(c, true_color),
+ // Otherwise, use a specific fallback color.
+ None => Some(Fixed(DEFAULT_GUTTER_COLOR)),
+ },
+ ..Style::default()
+ };
Colors {
- grid: gutter_color.normal(),
- rule: gutter_color.normal(),
+ grid: gutter_style,
+ rule: gutter_style,
filename: Style::new().bold(),
git_added: Green.normal(),
git_removed: Red.normal(),
git_modified: Yellow.normal(),
- line_number: gutter_color.normal(),
+ line_number: gutter_style,
}
}
}