-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Don't add artificial newline to last line if --style=plain #1440
Don't add artificial newline to last line if --style=plain #1440
Conversation
I'd say the fix definitely should include some integration tests too, but before I put too much time into that, I just wanted to check if this fix looks reasonable to you? |
Thank you for your contribution!
It does! :-) The "Test with new syntaxes and themes" currently fails in the syntax regression tests, as there are some files without newlines at the end. This should be fixed anyway (trailing newlines should be added). |
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 sharkdp#1438 since otherwise the \n will be missing with --style=plain, since we will stop adding it if it is missing.
This fixes sharkdp#1438. Note however, that using a pager such as less will add a newline itself. So to actually not print a newline for such files, you need to either disable paging: bat --style=plain --paging=never no-newline-at-end-of-file.txt or use a "pager" that does not add a newline: bat --style=plain --pager=cat no-newline-at-end-of-file.txt Note that we also update syntax tests file since a bunch of them had missing newlines on the last lines.
652a0b0
to
68d525c
Compare
Just a quick status update. I've pushed a set of commits that (should) pass all existing tests. Feel free to code-review if you wish. However, to add new tests for this usecase, I need to come up with a way to test tty output. From what I can tell, only non-tty output is tested in So it seems to me as if the right course of action is to add support for tty-output-testing to If you have idea for other approaches, I am all ears. |
I don't think we need to mock a complete terminal to test this. We can force I added a test that fails on master but succeeds on your branch. The changes here look great - thank you very much! |
Thanks a lot for the help with adding a test for this fix! I found no dedicated regression test for the fix for #299, so I added such a test in PR #1445. The new test fails if the fix for #299 is reverted from master, but of course pass on unmodified master. It is true that we can force bat options to behave as if a tty was used, but I still think tests for tty defaults has some merit. There is currently no test that fails if we mess up the code paths that depends on e.g. |
👍
Interesting thoughts. I agree in general. It would be great to see an explicit example where such a test would be superior over forcing colorized/decorated output.. even if constructed.
Yes, I think that should be discussed in a new ticket 👍 |
This fixes #1438.
Note however, that using a pager such as less will add a newline itself.
So to actually not print a newline for such files, you need to either
disable paging:
bat --style=plain --paging=never no-newline-at-end-of-file.txt
or use a "pager" that does not add a newline:
bat --style=plain --pager=cat no-newline-at-end-of-file.txt