diff options
author | Thomas Otto <th1000s@posteo.net> | 2021-04-18 15:59:27 +0200 |
---|---|---|
committer | Thomas Otto <th1000s@posteo.net> | 2021-04-19 22:37:41 +0200 |
commit | 730843c2f63ad36892d59b260e93cc3d4fe4f52b (patch) | |
tree | 5e760d02ee0e64e73410228f4d1f4984e9ec8b4e | |
parent | 1281db2ca3f59214cef61a35e587a9c25238c25c (diff) |
zero block highlighting fixed, clippy, misc.
-rw-r--r-- | src/config.rs | 8 | ||||
-rw-r--r-- | src/features/side_by_side_wrap.rs | 14 | ||||
-rw-r--r-- | src/paint.rs | 30 |
3 files changed, 27 insertions, 25 deletions
diff --git a/src/config.rs b/src/config.rs index def35527..9404c5e4 100644 --- a/src/config.rs +++ b/src/config.rs @@ -262,13 +262,7 @@ impl From<cli::Opt> for Config { // TODO, support multi-character symbols, and thus store // right_align_symbol_len here? use_wrap_right_permille: { - let percent = if opt.side_by_side_wrap_right_percent < 0.0 { - 0.0 - } else if opt.side_by_side_wrap_right_percent > 100.0 { - 100.0 - } else { - opt.side_by_side_wrap_right_percent - }; + let percent = opt.side_by_side_wrap_right_percent.clamp(0.0, 100.0); (percent * 10.0).round() as usize }, max_lines: opt.side_by_side_wrap_max_lines, diff --git a/src/features/side_by_side_wrap.rs b/src/features/side_by_side_wrap.rs index bce9cfc9..20891e8d 100644 --- a/src/features/side_by_side_wrap.rs +++ b/src/features/side_by_side_wrap.rs @@ -16,6 +16,8 @@ pub struct WrapConfig { pub wrap_symbol: String, pub wrap_right_symbol: String, pub right_align_symbol: String, + // In fractions of 1000 so that a >100 wide panel can + // still be configured down to a single character. pub use_wrap_right_permille: usize, pub max_lines: usize, } @@ -194,9 +196,9 @@ where if result.is_empty() { result.push(Vec::new()); } - result - .last_mut() - .map(|vec| vec.extend(stack.into_iter().rev())); + + // unwrap: previous `if` ensures result can not be empty + result.last_mut().unwrap().extend(stack.into_iter().rev()); } result @@ -461,7 +463,11 @@ pub fn wrap_zero_block<'c: 'a, 'a>( &config, diff_style_sections.into_iter().flatten(), line_width, - &config.null_style, + // To actually highlight `config.inline_hint_color` characters: + &Style { + is_syntax_highlighted: true, + ..config.null_style + }, &None, ); diff --git a/src/paint.rs b/src/paint.rs index 68fc389a..191160bd 100644 --- a/src/paint.rs +++ b/src/paint.rs @@ -164,13 +164,6 @@ impl<'a> Painter<'a> { Self::get_diff_style_sections(&self.minus_lines, &self.plus_lines, self.config); if self.config.side_by_side { - let avail_width = available_line_width(&self.config, &self.line_numbers_data); - - let right_panel_too_long = self - .plus_lines - .iter() - .any(|(line, _)| side_by_side::line_is_too_long(&line, avail_width.right)); - let syntax_left_right = LeftRight::new( minus_line_syntax_style_sections, plus_line_syntax_style_sections, @@ -199,13 +192,22 @@ impl<'a> Painter<'a> { // the truncation symbol. And to be consistent, use spaces for the entire // block. - // TODO, see prev. patch - if right_panel_too_long { - // BgFillWidth::CfgDefault(BgFillMethod::Spaces) - BgFillWidth::CfgDefault(BgFillMethod::TryAnsiSequence) - } else { - BgFillWidth::CfgDefault(BgFillMethod::TryAnsiSequence) - }, + // TODO, see "background extending" patch + /* + + let avail_width = available_line_width(&self.config, &self.line_numbers_data); + let right_panel_too_long = self + .plus_lines + .iter() + .any(|(line, _)| side_by_side::line_is_too_long(&line, avail_width.right)); + + if right_panel_too_long { + // BgFillWidth::CfgDefault(BgFillMethod::Spaces) + BgFillWidth::CfgDefault(BgFillMethod::TryAnsiSequence) + } else { + BgFillWidth::CfgDefault(BgFillMethod::TryAnsiSequence) + }, */ + BgFillWidth::CfgDefault(BgFillMethod::TryAnsiSequence), ); // Only set `should_wrap` to true if wrapping is wanted and lines which are |