Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A blank line at the end of output. #379

Closed
nb5p opened this issue Oct 25, 2018 · 6 comments · Fixed by #449
Closed

A blank line at the end of output. #379

nb5p opened this issue Oct 25, 2018 · 6 comments · Fixed by #449
Labels
bug

Comments

@nb5p
Copy link

@nb5p nb5p commented Oct 25, 2018

When using the “--style plain” parameter, there will be a blank line at the end of the output.

@sharkdp

This comment has been minimized.

Copy link
Owner

@sharkdp sharkdp commented Oct 25, 2018

Thank you for reporting this!

@sharkdp

This comment has been minimized.

Copy link
Owner

@sharkdp sharkdp commented Oct 25, 2018

Hm.. I think this is actually caused by less somehow. Everything is alright if we set --paging=never.

Edit: this is caused by the combination of ANSI codes that are printed by bat and the usage of less. If we set --color=never, the issue is also gone.

@teresaejunior

This comment has been minimized.

Copy link

@teresaejunior teresaejunior commented Nov 28, 2018

Couldn't this be related to #434? Maybe there is an extra newline when using with --plain?

@sharkdp

This comment has been minimized.

Copy link
Owner

@sharkdp sharkdp commented Dec 14, 2018

Couldn't this be related to #434? Maybe there is an extra newline when using with --plain?

No, I don't think it is related.

I think the problem is the following.

Say we have a file "test.md" with content "foo":

echo foo > test.md

When we output this file via bat, we see the wrong behavior (notice the additional empty line):

▶ bat -p test.md ; echo test 
foo

test

To see what bat actually outputs, we can pipe it's output to bat -A which shows all non-printable characters (we have to use --color=always to make sure that it still outputs ANSI codes):

▶ bat --color=always -p test.md | bat -Ap
␛[38;2;255;255;255mfoo␊
␛[0m

We can see that bat outputs the ANSI sequence ␛[38;2;255;255;255m to set the foreground color to white. Then, it outputs foo␊, i.e. the full first line of the file (including the newline / line-feed). Finally, it outputs the ANSI sequence ␛[0m to reset the foreground color.

I think it is this additional (empty) line including the ␛[0m sequence which trips up less. Again, notice that everything is fine if we disable the pager:

▶ bat --paging=never -p test.md ; echo test
foo
test
@sharkdp

This comment has been minimized.

Copy link
Owner

@sharkdp sharkdp commented Dec 14, 2018

We can also confirm this by using printf:

▶ printf "\x1b[38;2;255;255;255mfoo\n\x1b[0m" | less -FRX; echo test 
foo

test

/tmp                                                                               
▶ printf "\x1b[38;2;255;255;255mfoo\n\x1b[0m"; echo test            
foo
test

We could potentially fix this inside bat by moving the ANSI reset-code before the newline:

▶ printf "\x1b[38;2;255;255;255mfoo\x1b[0m\n" | less -FRX; echo test
foo
test
sharkdp added a commit that referenced this issue Dec 14, 2018
fixes #379
@sharkdp sharkdp closed this in #449 Dec 14, 2018
sharkdp added a commit that referenced this issue Dec 14, 2018
@sharkdp

This comment has been minimized.

Copy link
Owner

@sharkdp sharkdp commented Feb 8, 2019

Fixed in v0.10.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.