mirror of https://github.com/sharkdp/bat.git
replace_nonprintable: Keep \n around
Since it has a functional role, we can not just replace it, we must keep it around. This also allows us to simplify the code slightly. We must fix this before we fix #1438 since otherwise the \n will be missing with --style=plain, since we will stop adding it if it is missing.
This commit is contained in:
parent
f3489ffa29
commit
c3fc1b88fe
|
@ -72,7 +72,7 @@ pub fn replace_nonprintable(input: &[u8], tab_width: usize) -> String {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// line feed
|
// line feed
|
||||||
'\x0A' => output.push('␊'),
|
'\x0A' => output.push_str("␊\x0A"),
|
||||||
// carriage return
|
// carriage return
|
||||||
'\x0D' => output.push('␍'),
|
'\x0D' => output.push('␍'),
|
||||||
// null
|
// null
|
||||||
|
|
|
@ -91,9 +91,6 @@ impl<'a> Printer for SimplePrinter<'a> {
|
||||||
if self.config.show_nonprintable {
|
if self.config.show_nonprintable {
|
||||||
let line = replace_nonprintable(line_buffer, self.config.tab_width);
|
let line = replace_nonprintable(line_buffer, self.config.tab_width);
|
||||||
write!(handle, "{}", line)?;
|
write!(handle, "{}", line)?;
|
||||||
if line_buffer.last() == Some(&b'\n') {
|
|
||||||
writeln!(handle)?;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
handle.write_all(line_buffer)?
|
handle.write_all(line_buffer)?
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue