Merge pull request #1440 from Enselic/fix-1438-newline-can-be-added-even-if-style-plain
Don't add artificial newline to last line if --style=plain
commitcc7b89faf822d773a5ec74f3c80320ff06863af8
authorDavid Peter <sharkdp@users.noreply.github.com>
dateMon 21 Dec 2020, 09:24 (6 years ago)
parentc1e47463e9afe2
CHANGELOG.md+2−1
@@ -5,7 +5,8 @@
55
66## Bugfixes
77
8−- only print themes hint in interactive mode (`bat --list-themes`), see #1439 (@rsteube)
8+- If the last line doesn't end with a newline character, don't add it if `--style=plain`, see #1438 (@Enselic)
9+- Only print themes hint in interactive mode (`bat --list-themes`), see #1439 (@rsteube)
910- Make ./tests/syntax-tests/regression_test.sh work on recent versions of macOS, see #1443 (@Enselic)
1011
1112## Other
src/preprocessor.rs+1−1
@@ -72,7 +72,7 @@ pub fn replace_nonprintable(input: &[u8], tab_width: usize) -> String {
7272 }
7373 }
7474 // line feed
75− '\x0A' => output.push('␊'),
75+ '\x0A' => output.push_str("␊\x0A"),
7676 // carriage return
7777 '\x0D' => output.push('␍'),
7878 // null
src/printer.rs+1−4
@@ -91,9 +91,6 @@ impl<'a> Printer for SimplePrinter<'a> {
9191 if self.config.show_nonprintable {
9292 let line = replace_nonprintable(line_buffer, self.config.tab_width);
9393 write!(handle, "{}", line)?;
94− if line_buffer.last() == Some(&b'\n') {
95− writeln!(handle)?;
96− }
9794 } else {
9895 handle.write_all(line_buffer)?
9996 };
@@ -463,7 +460,7 @@ impl<'a> Printer for InteractivePrinter<'a> {
463460 }
464461 }
465462
466− if line.bytes().next_back() != Some(b'\n') {
463+ if !self.config.style_components.plain() && line.bytes().next_back() != Some(b'\n') {
467464 writeln!(handle)?;
468465 }
469466 } else {
tests/integration_tests.rs+14
@@ -813,3 +813,17 @@ fn show_all_mode() {
813813 .stdout("hello·world␊\n├──┤␍␀␇␈␛")
814814 .stderr("");
815815}
816+
817+#[test]
818+fn plain_mode_does_not_add_nonexisting_newline() {
819+ bat()
820+ .arg("--paging=never")
821+ .arg("--color=never")
822+ .arg("--decorations=always")
823+ .arg("--style=plain")
824+ .arg("single-line.txt")
825+ .assert()
826+ .success()
827+ .stdout("Single Line");
828+}
829+
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.