Skip to content

Commit

Permalink
zero block highlighting fixed, clippy, misc.
Browse files Browse the repository at this point in the history
  • Loading branch information
th1000s committed Apr 18, 2021
1 parent 0dcb00b commit 93b284c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 25 deletions.
8 changes: 1 addition & 7 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
14 changes: 10 additions & 4 deletions src/features/side_by_side_wrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
);

Expand Down
30 changes: 16 additions & 14 deletions src/paint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 93b284c

Please sign in to comment.