From b5c0223e781cc248d85450bed4408b3b9b36d70f Mon Sep 17 00:00:00 2001 From: Dan Davison Date: Sat, 20 Nov 2021 14:13:57 -0500 Subject: Set is_emph explicitly on *-emph-styles This addresses a bug triggered by doing things like minus-style = minus-emph-style That was causing the is_emph bit to be set on minus-style, with undesirable consequences. --- src/parse_styles.rs | 50 ++++++++++++++------------------------------------ 1 file changed, 14 insertions(+), 36 deletions(-) (limited to 'src/parse_styles.rs') diff --git a/src/parse_styles.rs b/src/parse_styles.rs index 538b333a..197b2694 100644 --- a/src/parse_styles.rs +++ b/src/parse_styles.rs @@ -24,13 +24,7 @@ pub fn parse_styles(opt: &cli::Opt) -> HashMap { make_line_number_styles(opt, &mut styles); styles.insert( "inline-hint-style", - style_from_str( - &opt.inline_hint_style, - None, - None, - opt.computed.true_color, - false, - ), + style_from_str(&opt.inline_hint_style, None, None, opt.computed.true_color), ); styles.insert( "git-minus-style", @@ -46,7 +40,10 @@ pub fn parse_styles(opt: &cli::Opt) -> HashMap { _ => *style::GIT_DEFAULT_PLUS_STYLE, }), ); - resolve_style_references(styles, opt) + let mut resolved_styles = resolve_style_references(styles, opt); + resolved_styles.get_mut("minus-emph-style").unwrap().is_emph = true; + resolved_styles.get_mut("plus-emph-style").unwrap().is_emph = true; + resolved_styles } fn resolve_style_references( @@ -112,7 +109,6 @@ fn make_hunk_styles<'a>(opt: &'a cli::Opt, styles: &'a mut HashMap<&str, StyleRe )), None, true_color, - false, ); let minus_emph_style = style_from_str( @@ -126,11 +122,9 @@ fn make_hunk_styles<'a>(opt: &'a cli::Opt, styles: &'a mut HashMap<&str, StyleRe )), None, true_color, - true, ); - let minus_non_emph_style = - style_from_str(&opt.minus_non_emph_style, None, None, true_color, false); + let minus_non_emph_style = style_from_str(&opt.minus_non_emph_style, None, None, true_color); // The style used to highlight a removed empty line when otherwise it would be invisible due to // lack of background color in minus-style. @@ -145,10 +139,9 @@ fn make_hunk_styles<'a>(opt: &'a cli::Opt, styles: &'a mut HashMap<&str, StyleRe )), None, true_color, - false, ); - let zero_style = style_from_str(&opt.zero_style, None, None, true_color, false); + let zero_style = style_from_str(&opt.zero_style, None, None, true_color); let plus_style = style_from_str( &opt.plus_style, @@ -161,7 +154,6 @@ fn make_hunk_styles<'a>(opt: &'a cli::Opt, styles: &'a mut HashMap<&str, StyleRe )), None, true_color, - false, ); let plus_emph_style = style_from_str( @@ -175,11 +167,9 @@ fn make_hunk_styles<'a>(opt: &'a cli::Opt, styles: &'a mut HashMap<&str, StyleRe )), None, true_color, - true, ); - let plus_non_emph_style = - style_from_str(&opt.plus_non_emph_style, None, None, true_color, false); + let plus_non_emph_style = style_from_str(&opt.plus_non_emph_style, None, None, true_color); // The style used to highlight an added empty line when otherwise it would be invisible due to // lack of background color in plus-style. @@ -194,11 +184,10 @@ fn make_hunk_styles<'a>(opt: &'a cli::Opt, styles: &'a mut HashMap<&str, StyleRe )), None, true_color, - false, ); let whitespace_error_style = - style_from_str(&opt.whitespace_error_style, None, None, true_color, false); + style_from_str(&opt.whitespace_error_style, None, None, true_color); styles.extend([ ("minus-style", minus_style), @@ -220,19 +209,19 @@ fn make_hunk_styles<'a>(opt: &'a cli::Opt, styles: &'a mut HashMap<&str, StyleRe fn make_line_number_styles(opt: &cli::Opt, styles: &mut HashMap<&str, StyleReference>) { let true_color = opt.computed.true_color; let line_numbers_left_style = - style_from_str(&opt.line_numbers_left_style, None, None, true_color, false); + style_from_str(&opt.line_numbers_left_style, None, None, true_color); let line_numbers_minus_style = - style_from_str(&opt.line_numbers_minus_style, None, None, true_color, false); + style_from_str(&opt.line_numbers_minus_style, None, None, true_color); let line_numbers_zero_style = - style_from_str(&opt.line_numbers_zero_style, None, None, true_color, false); + style_from_str(&opt.line_numbers_zero_style, None, None, true_color); let line_numbers_plus_style = - style_from_str(&opt.line_numbers_plus_style, None, None, true_color, false); + style_from_str(&opt.line_numbers_plus_style, None, None, true_color); let line_numbers_right_style = - style_from_str(&opt.line_numbers_right_style, None, None, true_color, false); + style_from_str(&opt.line_numbers_right_style, None, None, true_color); styles.extend([ ("line-numbers-minus-style", line_numbers_minus_style), @@ -253,7 +242,6 @@ fn make_commit_file_hunk_header_styles(opt: &cli::Opt, styles: &mut HashMap<&str Some(&opt.commit_decoration_style), opt.deprecated_commit_color.as_deref(), true_color, - false, ) ), ("file-style", @@ -263,7 +251,6 @@ fn make_commit_file_hunk_header_styles(opt: &cli::Opt, styles: &mut HashMap<&str Some(&opt.file_decoration_style), opt.deprecated_file_color.as_deref(), true_color, - false, ) ), ("hunk-header-style", @@ -273,7 +260,6 @@ fn make_commit_file_hunk_header_styles(opt: &cli::Opt, styles: &mut HashMap<&str Some(&opt.hunk_header_decoration_style), opt.deprecated_hunk_color.as_deref(), true_color, - false, ) ), ("hunk-header-file-style", @@ -282,7 +268,6 @@ fn make_commit_file_hunk_header_styles(opt: &cli::Opt, styles: &mut HashMap<&str None, None, true_color, - false, ) ), ("hunk-header-line-number-style", @@ -291,7 +276,6 @@ fn make_commit_file_hunk_header_styles(opt: &cli::Opt, styles: &mut HashMap<&str None, None, true_color, - false, ) ), ]); @@ -302,7 +286,6 @@ fn style_from_str( default: Option