Fix side-by-side line length when colour is disabled

Fixes #406

Looks like this was inadvertently broken in #301.
pull/402/head
Wilfred Hughes 2022-10-14 13:15:17 +07:00
parent 2a6eb7e4f8
commit b4ff28c75e
2 changed files with 14 additions and 4 deletions

@ -24,6 +24,11 @@ displayed.
`--list-languages` now respects the value of `--color`, whose default
only uses styling when stdout is a TTY.
### Display
Fixed side-by-side display width when color is disabled (when piping
difftastic stdout or with `--color=never`).
### Build
Fixed an issue with building on Windows with gcc.

@ -106,15 +106,20 @@ pub fn split_and_apply(
assert!(max_len > 0);
if styles.is_empty() && !line.trim().is_empty() {
// Missing styles is a bug, so highlight in purple to make this obvious.
return split_string_by_width(line, max_len, matches!(side, Side::Left))
.into_iter()
.map(|(part, _)| {
.map(|(part, pad)| {
let mut res = String::with_capacity(part.len() + pad);
if use_color {
highlight_missing_style_bug(part)
// If we're syntax highlighting and have no
// styles, that's a bug.
res.push_str(&highlight_missing_style_bug(part));
} else {
part.to_owned()
res.push_str(part);
}
res.push_str(&" ".repeat(pad));
res
})
.collect();
}