sharkdp / bat

A cat(1) clone with wings.
Apache License 2.0
49.31k stars 1.25k forks source link

Output differs (and is wrong) from cat on colored file from stark/Color-Scripts #771

Closed ericonr closed 4 years ago

ericonr commented 4 years ago

I was taking a look at the colored terminal scripts from stark/Color-Scripts, and one of them was, instead of a script, a text file that had to be printed to STDOUT to be visualized. It was the crowns file. Using cat on it yields the correct result, but using bat yields a wrong result, both on Alacritty and Konsole, both with bash and fish, and with or without the -p flag for plain output.

The output from both commands can be seen in this asciinema.

EDIT:

bat version: 0.12.1

After a bit more investigating I tried running it with the pager disabled:

bat --paging=never crowns

which actually fixed the issue, even if there shouldn't have been a pager involved, because the output easily fit into the buffer.

By changing the PAGER environment variable to more, I got even weirder output, so it seems bat calls a pager anyway (unless paging is set to never), possibly with some flags that make it not page unless the output is big enough to need it, which seems unnecessary to me.

I will file a bug report with less and more developers, because both have weird output, even if they show the colors:

more crowns

or

less --RAW-CONTROL-CHARS crowns
sharkdp commented 4 years ago

After a bit more investigating I tried running it with the pager disabled:

bat --paging=never crowns

:+1:

even if there shouldn't have been a pager involved, because the output easily fit into the buffer.

We always call the pager. The may then decide to exit early if the output fits on one screen. bat can not make that decision, as we want bat to be unbuffered ( we want to print one output line for each input line).

sharkdp commented 4 years ago

By the way: note that you can use bat -pp … to quickly disable the pager in case you experience problems with the pager in the future.

ericonr commented 4 years ago

Ok, thanks!