Don't add artificial newline to last line if --style=plain
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
Note that we also update syntax tests file since a bunch of them had
missing newlines on the last lines.
commit68d525cd8b350b40e2c990c70625eba4e82f746d
authorMartin Nordholts <enselic@gmail.com>
dateWed 16 Dec 2020, 19:22 (6 years ago)
parentc3fc1b8
CHANGELOG.md+2
@@ -5,6 +5,8 @@
55
66## Bugfixes
77
8+- If the last line doesn't end with a newline character, don't add it if `--style=plain`, see #1438 (@Enselic)
9+
810## Other
911
1012## Syntaxes
src/printer.rs+1−1
@@ -460,7 +460,7 @@ impl<'a> Printer for InteractivePrinter<'a> {
460460 }
461461 }
462462
463− if line.bytes().next_back() != Some(b'\n') {
463+ if !self.config.style_components.plain() && line.bytes().next_back() != Some(b'\n') {
464464 writeln!(handle)?;
465465 }
466466 } else {
tests/syntax-tests/highlighted/Plaintext/plaintext.txt+1−1
@@ -175,4 +175,4 @@
175175[38;2;117;113;94m\u{ad}[0m[38;2;249;38;114m␊[0m
176176[38;2;117;113;94m\u{ae}[0m[38;2;249;38;114m␊[0m
177177[38;2;249;38;114m␊[0m
178−[38;2;248;248;242mHere's[0m[38;2;102;217;239m·[0m[38;2;248;248;242ma[0m[38;2;102;217;239m·[0m[38;2;248;248;242mline[0m[38;2;102;217;239m·[0m[38;2;248;248;242mwith[0m[38;2;102;217;239m·[0m[38;2;248;248;242mmultiple[0m[38;2;102;217;239m·[0m[38;2;248;248;242mcharacters.[0m
178+[38;2;248;248;242mHere's[0m[38;2;102;217;239m·[0m[38;2;248;248;242ma[0m[38;2;102;217;239m·[0m[38;2;248;248;242mline[0m[38;2;102;217;239m·[0m[38;2;248;248;242mwith[0m[38;2;102;217;239m·[0m[38;2;248;248;242mmultiple[0m[38;2;102;217;239m·[0m[38;2;248;248;242mcharacters.[0m[38;2;249;38;114m␊[0m
tests/syntax-tests/source/ActionScript/test.as+1−1
@@ -72,4 +72,4 @@ package TestSyntax {
7272 var sndChannel:SoundChannel = mySound.play();
7373 }
7474 }
75−}
75+}
tests/syntax-tests/source/Batch/build.bat+1−1
@@ -56,4 +56,4 @@ set LDLIBS= ^
5656 @set "LINK_FILES=%LINK_FILES% %%~f"
5757)
5858
59−lld-link.exe %LINK_FILES% -out:"%OUTPUT%" %LDFLAGS% %LDLIBS%
59+lld-link.exe %LINK_FILES% -out:"%OUTPUT%" %LDFLAGS% %LDLIBS%
tests/syntax-tests/source/Clojure/test.clj+1−1
@@ -55,4 +55,4 @@
5555 (println (factorial 5))
5656 (log)
5757 (log "Message"))
58−
58+
tests/syntax-tests/source/Dockerfile/Dockerfile+1−1
@@ -16,4 +16,4 @@ EXPOSE 80/tcp
1616
1717VOLUME [/var/lib/mysql/data]
1818
19−ENTRYPOINT ["/usr/bin/entrypoint.sh"]
19+ENTRYPOINT ["/usr/bin/entrypoint.sh"]
tests/syntax-tests/source/Git Attributes/example.gitattributes+1−1
@@ -13,4 +13,4 @@
1313*.patch -text
1414
1515.gitattributes linguist-language=gitattributes
16−.gitkeep export-ignore
16+.gitkeep export-ignore
tests/syntax-tests/source/Git Config/text.gitconfig+1−1
@@ -104,4 +104,4 @@
104104[user]
105105 email = f.nord@example.com
106106 name = Frank Nord
107− signingkey = AAAAAAAAAAAAAAAA
107+ signingkey = AAAAAAAAAAAAAAAA
tests/syntax-tests/source/Hosts/hosts+1−1
@@ -5,4 +5,4 @@
55192.160.0.200 try.sample.test try #another comment
66216.58.223.238 google.com
77
8−::1 localhost.try ip6-localhost
8+::1 localhost.try ip6-localhost
tests/syntax-tests/source/Makefile/Makefile+1−1
@@ -382,4 +382,4 @@ install: all
382382 @ln -sf $(REDIS_SERVER_NAME) $(INSTALL_BIN)/$(REDIS_SENTINEL_NAME)
383383
384384uninstall:
385− rm -f $(INSTALL_BIN)/{$(REDIS_SERVER_NAME),$(REDIS_BENCHMARK_NAME),$(REDIS_CLI_NAME),$(REDIS_CHECK_RDB_NAME),$(REDIS_CHECK_AOF_NAME),$(REDIS_SENTINEL_NAME)}
385+ rm -f $(INSTALL_BIN)/{$(REDIS_SERVER_NAME),$(REDIS_BENCHMARK_NAME),$(REDIS_CLI_NAME),$(REDIS_CHECK_RDB_NAME),$(REDIS_CHECK_AOF_NAME),$(REDIS_SENTINEL_NAME)}
tests/syntax-tests/source/PHP/test.php+1−1
@@ -108,4 +108,4 @@ $doe->setName('John Doe');
108108
109109$ending = 2 > 3 ? "yep" : "nah";
110110
111−?>
111+?>
tests/syntax-tests/source/Plaintext/plaintext.txt
Binary file not shown.
tests/syntax-tests/source/PowerShell/test.ps1
Binary file not shown.
tests/syntax-tests/source/RequirementsTXT/requirements.txt+1−1
@@ -5,4 +5,4 @@ pywheels>=12.4 #a whitespace followed by comments
55Nuitka<0.6.8.4
66wxPython>=1.0, <=2.1
77
8−#this is another comment
8+#this is another comment
tests/syntax-tests/source/YAML/example.yaml+1−1
@@ -31,4 +31,4 @@ emails:
3131 - bob@example.com
3232 - bill@example.com
3333 supervisors:
34− - george@example.com
34+ - george@example.com
tests/syntax-tests/source/reStructuredText/reference.rst+1−1
@@ -317,4 +317,4 @@ blank lines before and after.)
317317..
318318
319319 So this block is not "lost",
320− despite its indentation.
320+ despite its indentation.