Example:
$ echo -n deadbeef > test.txt
$ bat --wrap=never test.txt
ββββββββ¬βββββββββββββββββββββββββββββββββ
β File: test.txt
ββββββββΌβββββββββββββββββββββββββββββββββ
1 β deadbeefββββββββ΄βββββββββββββββββββββββββββββββββ
Compare that with --wrap=character (same input file):
$ bat test.txt
ββββββββ¬βββββββββββββββββββββββββββββββββ
β File: test.txt
ββββββββΌβββββββββββββββββββββββββββββββββ
1 β deadbeef
ββββββββ΄βββββββββββββββββββββββββββββββββ
I'm using 0.6.1 on Arch Linux:
$ bat --version
bat 0.6.1
It seems that this section is the culprit:
https://github.com/sharkdp/bat/blob/master/src/printer.rs#L230-L245
It simply prints the line as is, expecting that every line will be ended in a newline. But the last line can end without a newline, resulting in broken formatting.
It is possible to look at the last character and print the missing newline if there isn't one:
impl<'a> Printer for InteractivePrinter<'a> {
)).collect::<Vec<_>>()
.join("")
)?;
+
+ if line.bytes().next_back() != Some(0x0a) {
+ write!(handle, "\n")?;
+ }
} else {
for &(style, region) in regions.iter() {
let mut ansi_iterator = AnsiCodeIterator::new(region);
If you are okay with such solution, I would be happy to create a pull request!
Thank you for reporting this!
Your fix looks good (I would prefer b'\n' instead of 0x0a) - a PR would be very much appreciated!
Here you go: #300
Released in v0.7.0.
Most helpful comment
It seems that this section is the culprit:
https://github.com/sharkdp/bat/blob/master/src/printer.rs#L230-L245
It simply prints the line as is, expecting that every line will be ended in a newline. But the last line can end without a newline, resulting in broken formatting.
It is possible to look at the last character and print the missing newline if there isn't one:
If you are okay with such solution, I would be happy to create a pull request!