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 Something isn't working

Comments

@nb5p
Copy link

nb5p commented Oct 25, 2018

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

@sharkdp
Copy link
Owner

sharkdp commented Oct 25, 2018

Thank you for reporting this!

@sharkdp sharkdp added bug Something isn't working good first issue Good for newcomers Hacktoberfest and removed Hacktoberfest good first issue Good for newcomers labels Oct 25, 2018
@sharkdp
Copy link
Owner

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.

@admirabilis
Copy link

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

@sharkdp
Copy link
Owner

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
Copy link
Owner

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
Copy link
Owner

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
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants