diff options
author | Dan Davison <dandavison7@gmail.com> | 2020-07-10 00:21:16 -0400 |
---|---|---|
committer | Dan Davison <dandavison7@gmail.com> | 2020-07-10 00:21:16 -0400 |
commit | 8b7884285968f6836a0c676772a8195e74af1c36 (patch) | |
tree | 43da16f0c7f3afa1d4d45252b0b5e3fb75bb08f9 /src/paint.rs | |
parent | 192654c2c1fa00711fbb22d629c19bacbf0901a6 (diff) |
Refactor: compute fill styles from line type
Diffstat (limited to 'src/paint.rs')
-rw-r--r-- | src/paint.rs | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/src/paint.rs b/src/paint.rs index 40ed9c56..ccc5572b 100644 --- a/src/paint.rs +++ b/src/paint.rs @@ -147,8 +147,6 @@ impl<'a> Painter<'a> { } else { "" }, - self.config.minus_style, - self.config.minus_non_emph_style, Some(self.config.minus_empty_line_marker_style), None, ); @@ -166,8 +164,6 @@ impl<'a> Painter<'a> { } else { "" }, - self.config.plus_style, - self.config.plus_non_emph_style, Some(self.config.plus_empty_line_marker_style), None, ); @@ -199,8 +195,6 @@ impl<'a> Painter<'a> { self.config, &mut Some(&mut self.line_numbers_data), prefix, - self.config.zero_style, - self.config.zero_style, None, None, ); @@ -216,8 +210,6 @@ impl<'a> Painter<'a> { config: &config::Config, line_numbers_data: &mut Option<&mut line_numbers::LineNumbersData>, prefix: &str, - style: Style, // style for right fill if line contains no emph sections - non_emph_style: Style, // style for right fill if line contains emph sections empty_line_style: Option<Style>, // a style with background color to highlight an empty line background_color_extends_to_terminal_width: Option<bool>, ) { @@ -243,8 +235,7 @@ impl<'a> Painter<'a> { let (should_right_fill_background_color, fill_style) = Painter::get_should_right_fill_background_color_and_fill_style( diff_sections, - non_emph_style, - style, + state, background_color_extends_to_terminal_width, config, ); @@ -268,11 +259,18 @@ impl<'a> Painter<'a> { /// the style for doing so. fn get_should_right_fill_background_color_and_fill_style( diff_sections: &Vec<(Style, &str)>, - non_emph_style: Style, - style: Style, + state: &State, background_color_extends_to_terminal_width: Option<bool>, config: &config::Config, ) -> (bool, Style) { + // style: for right fill if line contains no emph sections + // non_emph_style: for right fill if line contains emph sections + let (style, non_emph_style) = match state { + State::HunkMinus => (config.minus_style, config.minus_non_emph_style), + State::HunkZero => (config.zero_style, config.zero_style), + State::HunkPlus => (config.plus_style, config.plus_non_emph_style), + _ => (config.null_style, config.null_style), + }; let fill_style = if style_sections_contain_more_than_one_style(diff_sections) { non_emph_style // line contains an emph section } else { |