diff options
author | Dan Davison <dandavison7@gmail.com> | 2021-11-20 14:13:57 -0500 |
---|---|---|
committer | Dan Davison <dandavison7@gmail.com> | 2021-11-21 12:27:51 -0500 |
commit | b5c0223e781cc248d85450bed4408b3b9b36d70f (patch) | |
tree | 40c61c341115cbe2fe95c31303315b8d1680aecf | |
parent | 7a64fa5a26314c05c811d7c1276388a4963fa0bd (diff) |
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.
-rw-r--r-- | src/parse_style.rs | 27 | ||||
-rw-r--r-- | src/parse_styles.rs | 50 | ||||
-rw-r--r-- | src/tests/ansi_test_utils.rs | 2 | ||||
-rw-r--r-- | src/tests/test_example_diffs.rs | 2 |
4 files changed, 23 insertions, 58 deletions
diff --git a/src/parse_style.rs b/src/parse_style.rs index 820cc036..6cdefe84 100644 --- a/src/parse_style.rs +++ b/src/parse_style.rs @@ -15,7 +15,6 @@ impl Style { default: Option<Self>, decoration_style_string: Option<&str>, true_color: bool, - is_emph: bool, ) -> Self { let (ansi_term_style, is_omitted, is_raw, is_syntax_highlighted) = parse_ansi_term_style(style_string, default, true_color); @@ -23,7 +22,7 @@ impl Style { DecorationStyle::from_str(decoration_style_string.unwrap_or(""), true_color); Self { ansi_term_style, - is_emph, + is_emph: false, is_omitted, is_raw, is_syntax_highlighted, @@ -32,7 +31,7 @@ impl Style { } pub fn from_git_str(git_style_string: &str) -> Self { - Self::from_str(git_style_string, None, None, true, false) + Self::from_str(git_style_string, None, None, true) } /// Construct Style but interpreting 'ul', 'box', etc as applying to the decoration style. @@ -41,17 +40,11 @@ impl Style { default: Option<Self>, decoration_style_string: Option<&str>, true_color: bool, - is_emph: bool, ) -> Self { let (special_attributes_from_style_string, style_string) = extract_special_decoration_attributes_from_non_decoration_style_string(style_string); - let mut style = Style::from_str( - &style_string, - default, - decoration_style_string, - true_color, - is_emph, - ); + let mut style = + Style::from_str(&style_string, default, decoration_style_string, true_color); // TODO: box in this context resulted in box-with-underline for commit and file style.decoration_style = DecorationStyle::apply_special_decoration_attributes( &mut style, @@ -68,14 +61,12 @@ impl Style { decoration_style_string: Option<&str>, deprecated_foreground_color_arg: Option<&str>, true_color: bool, - is_emph: bool, ) -> Self { let mut style = Self::from_str_with_handling_of_special_decoration_attributes( style_string, default, decoration_style_string, true_color, - is_emph, ); if let Some(s) = deprecated_foreground_color_arg { // The deprecated --{commit,file,hunk}-color args functioned to set the decoration @@ -530,7 +521,6 @@ mod tests { None, Some("ol red box bold green ul"), true, - false, ); let red_green_bold = ansi_term::Style { foreground: Some(ansi_term::Color::Red), @@ -550,7 +540,7 @@ mod tests { #[test] fn test_style_from_str_raw_with_box() { - let actual_style = Style::from_str("raw", None, Some("box"), true, false); + let actual_style = Style::from_str("raw", None, Some("box"), true); let empty_ansi_term_style = ansi_term::Style::new(); assert_eq!( actual_style, @@ -565,7 +555,7 @@ mod tests { #[test] fn test_style_from_str_decoration_style_only() { - let actual_style = Style::from_str("", None, Some("ol red box bold green ul"), true, false); + let actual_style = Style::from_str("", None, Some("ol red box bold green ul"), true); let red_green_bold = ansi_term::Style { foreground: Some(ansi_term::Color::Red), background: Some(ansi_term::Color::Green), @@ -588,7 +578,6 @@ mod tests { None, Some("ol red box bold green ul"), true, - false, ); let expected_decoration_style = DecorationStyle::BoxWithUnderOverline(ansi_term::Style { foreground: Some(ansi_term::Color::Red), @@ -612,7 +601,6 @@ mod tests { None, Some("box"), true, - false, ); let empty_ansi_term_style = ansi_term::Style::new(); assert_eq!( @@ -636,7 +624,7 @@ mod tests { ..ansi_term::Style::new() }); let actual_style = Style::from_str_with_handling_of_special_decoration_attributes_and_respecting_deprecated_foreground_color_arg( - "", None, Some("ol red box bold green ul"), None, true, false + "", None, Some("ol red box bold green ul"), None, true ); assert_eq!( actual_style, @@ -656,7 +644,6 @@ mod tests { Some("box"), None, true, - false, ); let empty_ansi_term_style = ansi_term::Style::new(); assert_eq!( 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<String, Style> { 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<String, Style> { _ => *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<Style>, decoration_style_string: Option<&str>, true_color: bool, - is_emph: bool, ) -> StyleReference { if is_style_reference(style_string) { StyleReference::Reference(style_string.to_owned()) @@ -312,7 +295,6 @@ fn style_from_str( default, decoration_style_string, true_color, - is_emph, )) } } @@ -322,7 +304,6 @@ fn style_from_str_with_handling_of_special_decoration_attributes( default: Option<Style>, decoration_style_string: Option<&str>, true_color: bool, - is_emph: bool, ) -> StyleReference { if is_style_reference(style_string) { StyleReference::Reference(style_string.to_owned()) @@ -333,7 +314,6 @@ fn style_from_str_with_handling_of_special_decoration_attributes( default, decoration_style_string, true_color, - is_emph, ), ) } @@ -345,7 +325,6 @@ fn style_from_str_with_handling_of_special_decoration_attributes_and_respecting_ decoration_style_string: Option<&str>, deprecated_foreground_color_arg: Option<&str>, true_color: bool, - is_emph: bool, ) -> StyleReference { if is_style_reference(style_string) { StyleReference::Reference(style_string.to_owned()) @@ -356,7 +335,6 @@ fn style_from_str_with_handling_of_special_decoration_attributes_and_respecting_ decoration_style_string, deprecated_foreground_color_arg, true_color, - is_emph )) } } diff --git a/src/tests/ansi_test_utils.rs b/src/tests/ansi_test_utils.rs index e63f0ea1..259c43b8 100644 --- a/src/tests/ansi_test_utils.rs +++ b/src/tests/ansi_test_utils.rs @@ -167,7 +167,7 @@ pub mod ansi_test_utils { ) -> bool { let line = output.lines().nth(line_number).unwrap(); assert!(ansi::strip_ansi_codes(line).starts_with(expected_prefix)); - let mut style = Style::from_str(expected_style, None, None, config.true_color, false); + let mut style = Style::from_str(expected_style, None, None, config.true_color); if _4_bit_color { style.ansi_term_style.foreground = style .ansi_term_style diff --git a/src/tests/test_example_diffs.rs b/src/tests/test_example_diffs.rs index a6d5f497..9b92af45 100644 --- a/src/tests/test_example_diffs.rs +++ b/src/tests/test_example_diffs.rs @@ -1471,7 +1471,7 @@ src/align.rs:71: impl<'a> Alignment<'a> { │ let output = integration_test_utils::run_delta(example_diff, &config); let line = output.lines().nth(8).unwrap(); if base_style_has_background_color { - let style = style::Style::from_str(base_style, None, None, true, false); + let style = style::Style::from_str(base_style, None, None, true); assert_eq!( line, &style |