diff options
author | Dan Davison <dandavison7@gmail.com> | 2020-03-01 13:13:18 -0600 |
---|---|---|
committer | Dan Davison <dandavison7@gmail.com> | 2020-03-01 16:25:10 -0600 |
commit | 37cc69ea434303ec8ebf4f248d4bd7f1febfe3e2 (patch) | |
tree | 9858059d214be7d3e9405d11403be418cc71f062 /src/style.rs | |
parent | eeee3d4732479295248b49164f8db58d3244b1ff (diff) |
Support 256-color terminal environments
Fixes #110
With this commit, delta enters "24 bit color mode" iff either of the
following are true:
1. The --24-bit-color command line option value is "always"
2. The --24-bit-color command line option value is "auto" and the
COLORTERM environment variable is set to "truecolor" or "24bit".
See
https://gist.github.com/XVilka/8346728#true-color-detection
https://github.com/sharkdp/bat/blob/7779d9f6221b3e98c43a43ceb5596ba285fdf4f8/src/bin/bat/app.rs#L29-L33
Otherwise, delta enters "8-bit color mode".
In "24 bit color mode", delta will
1. Emit 24-bit RGB color shell escape sequences that will only be
displayed correctly by a terminal application that supports 24 bit
colors.
2. Select default background colors that will only be displayed
correctly by a terminal application that supports 24 bit colors.
In "8-bit color mode", delta will
1. Emit color shell escape sequences specifying the entry in the ANSI
256 color palette that is closest (according to the ansi_colours
library) to the requested color.
2. Select default background colors that will work well in a terminal
application that supports 8-bit color but not 24-bit color.
Diffstat (limited to 'src/style.rs')
-rw-r--r-- | src/style.rs | 108 |
1 files changed, 100 insertions, 8 deletions
diff --git a/src/style.rs b/src/style.rs index ae483c8f..80256805 100644 --- a/src/style.rs +++ b/src/style.rs @@ -19,62 +19,154 @@ pub fn is_no_syntax_highlighting_theme_name(theme_name: &str) -> bool { theme_name.to_lowercase() == "none" } -pub const LIGHT_THEME_MINUS_COLOR: Color = Color { +pub fn get_minus_color_default(is_light_mode: bool, is_true_color: bool) -> Color { + match (is_light_mode, is_true_color) { + (true, true) => LIGHT_THEME_MINUS_COLOR, + (true, false) => LIGHT_THEME_MINUS_COLOR_256, + (false, true) => DARK_THEME_MINUS_COLOR, + (false, false) => DARK_THEME_MINUS_COLOR_256, + } +} + +pub fn get_minus_emph_color_default(is_light_mode: bool, is_true_color: bool) -> Color { + match (is_light_mode, is_true_color) { + (true, true) => LIGHT_THEME_MINUS_EMPH_COLOR, + (true, false) => LIGHT_THEME_MINUS_EMPH_COLOR_256, + (false, true) => DARK_THEME_MINUS_EMPH_COLOR, + (false, false) => DARK_THEME_MINUS_EMPH_COLOR_256, + } +} + +pub fn get_plus_color_default(is_light_mode: bool, is_true_color: bool) -> Color { + match (is_light_mode, is_true_color) { + (true, true) => LIGHT_THEME_PLUS_COLOR, + (true, false) => LIGHT_THEME_PLUS_COLOR_256, + (false, true) => DARK_THEME_PLUS_COLOR, + (false, false) => DARK_THEME_PLUS_COLOR_256, + } +} + +pub fn get_plus_emph_color_default(is_light_mode: bool, is_true_color: bool) -> Color { + match (is_light_mode, is_true_color) { + (true, true) => LIGHT_THEME_PLUS_EMPH_COLOR, + (true, false) => LIGHT_THEME_PLUS_EMPH_COLOR_256, + (false, true) => DARK_THEME_PLUS_EMPH_COLOR, + (false, false) => DARK_THEME_PLUS_EMPH_COLOR_256, + } +} + +const LIGHT_THEME_MINUS_COLOR: Color = Color { r: 0xff, g: 0xe0, b: 0xe0, a: 0xff, }; -pub const LIGHT_THEME_MINUS_EMPH_COLOR: Color = Color { +const LIGHT_THEME_MINUS_COLOR_256: Color = Color { + r: 224, + g: 0x00, + b: 0x00, + a: 0x00, +}; + +const LIGHT_THEME_MINUS_EMPH_COLOR: Color = Color { r: 0xff, g: 0xc0, b: 0xc0, a: 0xff, }; -pub const LIGHT_THEME_PLUS_COLOR: Color = Color { +const LIGHT_THEME_MINUS_EMPH_COLOR_256: Color = Color { + r: 217, + g: 0x00, + b: 0x00, + a: 0x00, +}; + +const LIGHT_THEME_PLUS_COLOR: Color = Color { r: 0xd0, g: 0xff, b: 0xd0, a: 0xff, }; -pub const LIGHT_THEME_PLUS_EMPH_COLOR: Color = Color { +const LIGHT_THEME_PLUS_COLOR_256: Color = Color { + r: 194, + g: 0x00, + b: 0x00, + a: 0x00, +}; + +const LIGHT_THEME_PLUS_EMPH_COLOR: Color = Color { r: 0xa0, g: 0xef, b: 0xa0, a: 0xff, }; -pub const DARK_THEME_MINUS_COLOR: Color = Color { +const LIGHT_THEME_PLUS_EMPH_COLOR_256: Color = Color { + r: 157, + g: 0x00, + b: 0x00, + a: 0x00, +}; + +const DARK_THEME_MINUS_COLOR: Color = Color { r: 0x3f, g: 0x00, b: 0x01, a: 0xff, }; -pub const DARK_THEME_MINUS_EMPH_COLOR: Color = Color { +const DARK_THEME_MINUS_COLOR_256: Color = Color { + r: 52, + g: 0x00, + b: 0x00, + a: 0x00, +}; + +const DARK_THEME_MINUS_EMPH_COLOR: Color = Color { r: 0x90, g: 0x10, b: 0x11, a: 0xff, }; -pub const DARK_THEME_PLUS_COLOR: Color = Color { +const DARK_THEME_MINUS_EMPH_COLOR_256: Color = Color { + r: 124, + g: 0x00, + b: 0x00, + a: 0x00, +}; + +const DARK_THEME_PLUS_COLOR: Color = Color { r: 0x00, g: 0x28, b: 0x00, a: 0xff, }; -pub const DARK_THEME_PLUS_EMPH_COLOR: Color = Color { +const DARK_THEME_PLUS_COLOR_256: Color = Color { + r: 22, + g: 0x00, + b: 0x00, + a: 0x00, +}; + +const DARK_THEME_PLUS_EMPH_COLOR: Color = Color { r: 0x00, g: 0x60, b: 0x00, a: 0xff, }; +const DARK_THEME_PLUS_EMPH_COLOR_256: Color = Color { + r: 28, + g: 0x00, + b: 0x00, + a: 0x00, +}; + /// A special color to specify that no color escape codes should be emitted. pub const NO_COLOR: Color = Color::BLACK; |