From c2bf4cd2ec0c947f1a3651a66678dd55f3c9c7a3 Mon Sep 17 00:00:00 2001 From: Dan Davison Date: Wed, 17 Jun 2020 09:34:44 -0400 Subject: Highlight whitespace errors --- src/cli.rs | 5 ++++ src/config.rs | 14 ++++++++++ src/paint.rs | 47 ++++++++++++++++++++++++++++++---- src/preset.rs | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/set_options.rs | 13 ++++++++++ 5 files changed, 149 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/cli.rs b/src/cli.rs index e91b7056..ec45fffb 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -415,6 +415,11 @@ pub struct Opt { #[structopt(long = "--plus-empty-line-marker-style", default_value = "normal auto")] pub plus_empty_line_marker_style: String, + /// Style for whitespace errors. Defaults to color.diff.whitespace if that is set in git + /// config, or else 'magenta reverse'. + #[structopt(long = "whitespace-error-style", default_value = "auto auto")] + pub whitespace_error_style: String, + #[structopt(long = "minus-color")] /// Deprecated: use --minus-style='normal my_background_color'. pub deprecated_minus_background_color: Option, diff --git a/src/config.rs b/src/config.rs index 794acc7d..e05d7b8c 100644 --- a/src/config.rs +++ b/src/config.rs @@ -72,6 +72,7 @@ pub struct Config { pub tab_width: usize, pub true_color: bool, pub tokenization_regex: Regex, + pub whitespace_error_style: Style, pub zero_style: Style, } @@ -215,6 +216,7 @@ impl From for Config { plus_emph_style, plus_non_emph_style, plus_empty_line_marker_style, + whitespace_error_style, ) = make_hunk_styles(&opt, is_light_mode, true_color); let (commit_style, file_style, hunk_header_style) = @@ -300,6 +302,7 @@ impl From for Config { tab_width: opt.tab_width, tokenization_regex, true_color, + whitespace_error_style, zero_style, } } @@ -319,6 +322,7 @@ fn make_hunk_styles<'a>( Style, Style, Style, + Style, ) { let minus_style = Style::from_str( &opt.minus_style, @@ -416,6 +420,15 @@ fn make_hunk_styles<'a>( false, ); + let whitespace_error_style = Style::from_str( + &opt.whitespace_error_style, + None, + None, + None, + true_color, + false, + ); + ( minus_style, minus_emph_style, @@ -426,6 +439,7 @@ fn make_hunk_styles<'a>( plus_emph_style, plus_non_emph_style, plus_empty_line_marker_style, + whitespace_error_style, ) } diff --git a/src/paint.rs b/src/paint.rs index d9dddd62..7a98cd3d 100644 --- a/src/paint.rs +++ b/src/paint.rs @@ -332,13 +332,21 @@ impl<'a> Painter<'a> { } else { None }; - Self::update_styles(&mut diff_sections.0, minus_non_emph_style); + Self::update_styles( + &mut diff_sections.0, + config.whitespace_error_style, + minus_non_emph_style, + ); let plus_non_emph_style = if config.plus_non_emph_style != config.plus_emph_style { Some(config.plus_non_emph_style) } else { None }; - Self::update_styles(&mut diff_sections.1, plus_non_emph_style); + Self::update_styles( + &mut diff_sections.1, + config.whitespace_error_style, + plus_non_emph_style, + ); diff_sections } @@ -348,15 +356,30 @@ impl<'a> Painter<'a> { /// inferred edit operations and so, if there is a special non-emph style that is /// distinct from the default style, then it should be used for the non-emph style /// sections. - fn update_styles(style_sections: &mut Vec>, non_emph_style: Option