diff options
author | Dan Davison <dandavison7@gmail.com> | 2020-05-16 10:54:01 -0400 |
---|---|---|
committer | Dan Davison <dandavison7@gmail.com> | 2020-05-17 11:07:44 -0400 |
commit | 271e30cbdcc7fb480a443b3043776127cba810d3 (patch) | |
tree | 5b6ea81a5e5249e77a223015bf43baf2f3049536 /src/paint.rs | |
parent | 253bc3ac0fe34a8f08c2bf625fcc8bb78de01a4c (diff) |
Add new command-line options controlling foreground colors
- Revert "Do not expose new foreground color options yet"
This reverts commit 253bc3ac0fe34a8f08c2bf625fcc8bb78de01a4c.
- Make test assertions for minus_foreground_color
- Fix test: fix detection of foreground color
- Add diagnostic output to hunk highlighting test
- Disable syntax-highlighting if the user has set foreground colors
- Eliminate redundant style modifiers in config
- Revert fixed_foreground_style implementation
The syntax_style_sections will just contain syntect styles, or else a
dummy no-op style. All delta styles will be done in
diff_style_sections.
- Add more dimensions to grid in hunk highlighting test
- Support "none" as a value for background colors
- Set foreground colors in a way that's consistent with background colors
- Bug fix: don't highlight when there is no theme
Diffstat (limited to 'src/paint.rs')
-rw-r--r-- | src/paint.rs | 48 |
1 files changed, 11 insertions, 37 deletions
diff --git a/src/paint.rs b/src/paint.rs index b702ebe9..d05d4a47 100644 --- a/src/paint.rs +++ b/src/paint.rs @@ -34,6 +34,7 @@ impl<'a> Painter<'a> { assets: &'a HighlightingAssets, ) -> Self { let default_syntax = Self::get_syntax(config.syntax_set, None); + // TODO: Avoid setting these. let dummy_theme = &assets.theme_set.themes[style::DEFAULT_LIGHT_THEME]; let dummy_highlighter = HighlightLines::new(default_syntax, dummy_theme); Self { @@ -64,28 +65,16 @@ impl<'a> Painter<'a> { } pub fn paint_buffered_lines(&mut self) { - let minus_fixed_foreground_style = self.get_fixed_foreground_style( - self.config.minus_foreground_style_modifier, - self.config - .lines_to_be_syntax_highlighted - .contains(State::HunkMinus as usize), - ); - let plus_fixed_foreground_style = self.get_fixed_foreground_style( - self.config.plus_foreground_style_modifier, - self.config - .lines_to_be_syntax_highlighted - .contains(State::HunkPlus as usize), - ); let minus_line_syntax_style_sections = Self::get_syntax_style_sections_for_lines( &self.minus_lines, + self.config.should_syntax_highlight(&State::HunkMinus), &mut self.highlighter, - minus_fixed_foreground_style, self.config, ); let plus_line_syntax_style_sections = Self::get_syntax_style_sections_for_lines( &self.plus_lines, + self.config.should_syntax_highlight(&State::HunkPlus), &mut self.highlighter, - plus_fixed_foreground_style, self.config, ); let (minus_line_diff_style_sections, plus_line_diff_style_sections) = @@ -117,22 +106,6 @@ impl<'a> Painter<'a> { self.plus_lines.clear(); } - fn get_fixed_foreground_style( - &self, - foreground_style_modifier: Option<StyleModifier>, - should_syntax_highlight: bool, - ) -> Option<Style> { - match ( - foreground_style_modifier, - should_syntax_highlight, - self.config.theme, - ) { - (Some(style_modifier), _, _) => Some(self.config.no_style.apply(style_modifier)), - (_, true, Some(_)) => None, - _ => Some(self.config.no_style), - } - } - /// Superimpose background styles and foreground syntax /// highlighting styles, and write colored lines to output buffer. pub fn paint_lines( @@ -197,16 +170,16 @@ impl<'a> Painter<'a> { fn get_syntax_style_sections_for_lines<'s>( lines: &'s [String], + should_syntax_highlight: bool, highlighter: &mut HighlightLines, - fixed_style: Option<Style>, config: &config::Config, ) -> Vec<Vec<(Style, &'s str)>> { let mut line_sections = Vec::new(); for line in lines.iter() { line_sections.push(Painter::get_line_syntax_style_sections( - &line, + line, + should_syntax_highlight, highlighter, - fixed_style, &config, )); } @@ -215,13 +188,14 @@ impl<'a> Painter<'a> { pub fn get_line_syntax_style_sections( line: &'a str, + should_syntax_highlight: bool, highlighter: &mut HighlightLines, - fixed_style: Option<Style>, config: &config::Config, ) -> Vec<(Style, &'a str)> { - match fixed_style { - Some(fixed_style) => vec![(fixed_style, line)], - None => highlighter.highlight(line, &config.syntax_set), + if should_syntax_highlight && config.theme.is_some() { + highlighter.highlight(line, &config.syntax_set) + } else { + vec![(config.no_style, line)] } } |