diff options
author | Dan Davison <dandavison7@gmail.com> | 2020-05-20 22:46:08 -0400 |
---|---|---|
committer | Dan Davison <dandavison7@gmail.com> | 2020-05-22 22:45:37 -0400 |
commit | 2245582fbef18d94b0bef2fec3389f710dadc8d9 (patch) | |
tree | c3b70c9ec42e4ce95e0e26f807278eb636e70987 /src/style.rs | |
parent | 291d2fb7fa8cfc2a0886af895972326d00fb4dbe (diff) |
Implement hunk styles using style string arguments
- Do not apply foreground syntax style if it is "null syntect style"
This isn't really correct. We should find either a valid sentinel
value, or a way to only do the superimposing when we're doing
syntax-highlighting.
- Add --zero-style option (style for unchanged hunk lines)
- Implement --color-only using an option rewrite rule
Diffstat (limited to 'src/style.rs')
-rw-r--r-- | src/style.rs | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/src/style.rs b/src/style.rs index 0c6729cd..ede5d3da 100644 --- a/src/style.rs +++ b/src/style.rs @@ -1,4 +1,4 @@ -use ansi_term::Color; +use ansi_term::{Color, Style}; pub const LIGHT_THEMES: [&str; 5] = [ "GitHub", @@ -19,7 +19,7 @@ pub fn is_no_syntax_highlighting_theme_name(theme_name: &str) -> bool { theme_name.to_lowercase() == "none" } -pub fn get_minus_color_default(is_light_mode: bool, is_true_color: bool) -> Color { +pub fn get_minus_background_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, @@ -28,7 +28,7 @@ pub fn get_minus_color_default(is_light_mode: bool, is_true_color: bool) -> Colo } } -pub fn get_minus_emph_color_default(is_light_mode: bool, is_true_color: bool) -> Color { +pub fn get_minus_emph_background_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, @@ -37,7 +37,7 @@ pub fn get_minus_emph_color_default(is_light_mode: bool, is_true_color: bool) -> } } -pub fn get_plus_color_default(is_light_mode: bool, is_true_color: bool) -> Color { +pub fn get_plus_background_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, @@ -46,7 +46,7 @@ pub fn get_plus_color_default(is_light_mode: bool, is_true_color: bool) -> Color } } -pub fn get_plus_emph_color_default(is_light_mode: bool, is_true_color: bool) -> Color { +pub fn get_plus_emph_background_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, @@ -90,3 +90,13 @@ const DARK_THEME_PLUS_EMPH_COLOR_256: Color = Color::Fixed(28); /// A special color value to signify that the foreground color of a style should be derived from /// syntax highlighting. pub const SYNTAX_HIGHLIGHTING_COLOR: Color = Color::White; // TODO + +pub trait SyntaxHighlightable { + fn is_syntax_highlighted(&self) -> bool; +} + +impl SyntaxHighlightable for Style { + fn is_syntax_highlighted(&self) -> bool { + self.foreground == Some(SYNTAX_HIGHLIGHTING_COLOR) + } +} |