on master help sign in
Merge pull request #1440 from Enselic/fix-1438-newline-can-be-added-even-if-style-plain
cc7b89fDavid Peter
CHANGELOG.md+2−1
@@ -5,7 +5,8 @@
5
5
6## Bugfixes
6## Bugfixes
7
7
8+- If the last line doesn't end with a newline character, don't add it if `--style=plain`, see #1438 (@Enselic)
8−- only print themes hint in interactive mode (`bat --list-themes`), see #1439 (@rsteube)
9+- Only print themes hint in interactive mode (`bat --list-themes`), see #1439 (@rsteube)
9- Make ./tests/syntax-tests/regression_test.sh work on recent versions of macOS, see #1443 (@Enselic)
10- Make ./tests/syntax-tests/regression_test.sh work on recent versions of macOS, see #1443 (@Enselic)
10
11
11## Other
12## Other
src/preprocessor.rs+1−1
@@ -72,7 +72,7 @@ pub fn replace_nonprintable(input: &[u8], tab_width: usize) -> String {
72 }
72 }
73 }
73 }
74 // line feed
74 // line feed
75− '\x0A' => output.push('␊'),
75+ '\x0A' => output.push_str("␊\x0A"),
76 // carriage return
76 // carriage return
77 '\x0D' => output.push('␍'),
77 '\x0D' => output.push('␍'),
78 // null
78 // null
src/printer.rs+1−4
@@ -91,9 +91,6 @@ impl<'a> Printer for SimplePrinter<'a> {
91 if self.config.show_nonprintable {
91 if self.config.show_nonprintable {
92 let line = replace_nonprintable(line_buffer, self.config.tab_width);
92 let line = replace_nonprintable(line_buffer, self.config.tab_width);
93 write!(handle, "{}", line)?;
93 write!(handle, "{}", line)?;
94− if line_buffer.last() == Some(&b'\n') {
95− writeln!(handle)?;
96− }
97 } else {
94 } else {
98 handle.write_all(line_buffer)?
95 handle.write_all(line_buffer)?
99 };
96 };
@@ -463,7 +460,7 @@ impl<'a> Printer for InteractivePrinter<'a> {
463 }
460 }
464 }
461 }
465
462
466− if line.bytes().next_back() != Some(b'\n') {
463+ if !self.config.style_components.plain() && line.bytes().next_back() != Some(b'\n') {
467 writeln!(handle)?;
464 writeln!(handle)?;
468 }
465 }
469 } else {
466 } else {
tests/integration_tests.rs+14
@@ -813,3 +813,17 @@ fn show_all_mode() {
813 .stdout("hello·world␊\n├──┤␍␀␇␈␛")
813 .stdout("hello·world␊\n├──┤␍␀␇␈␛")
814 .stderr("");
814 .stderr("");
815}
815}
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 @@
175\u{ad}␊
175\u{ad}␊
176\u{ae}␊
176\u{ae}␊
177␊
177␊
178−Here's·a·line·with·multiple·characters.
178+Here's·a·line·with·multiple·characters.␊
tests/syntax-tests/source/ActionScript/test.as+1−1
@@ -72,4 +72,4 @@ package TestSyntax {
72 var sndChannel:SoundChannel = mySound.play();
72 var sndChannel:SoundChannel = mySound.play();
73 }
73 }
74 }
74 }
75−}
75+}
tests/syntax-tests/source/Batch/build.bat+1−1
@@ -56,4 +56,4 @@ set LDLIBS= ^
56 @set "LINK_FILES=%LINK_FILES% %%~f"
56 @set "LINK_FILES=%LINK_FILES% %%~f"
57)
57)
58
58
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 @@
55 (println (factorial 5))
55 (println (factorial 5))
56 (log)
56 (log)
57 (log "Message"))
57 (log "Message"))
58−
58+
tests/syntax-tests/source/Dockerfile/Dockerfile+1−1
@@ -16,4 +16,4 @@ EXPOSE 80/tcp
16
16
17VOLUME [/var/lib/mysql/data]
17VOLUME [/var/lib/mysql/data]
18
18
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 @@
13*.patch -text
13*.patch -text
14
14
15.gitattributes linguist-language=gitattributes
15.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 @@
104[user]
104[user]
105 email = f.nord@example.com
105 email = f.nord@example.com
106 name = Frank Nord
106 name = Frank Nord
107− signingkey = AAAAAAAAAAAAAAAA
107+ signingkey = AAAAAAAAAAAAAAAA
tests/syntax-tests/source/Hosts/hosts+1−1
@@ -5,4 +5,4 @@
5192.160.0.200 try.sample.test try #another comment
5192.160.0.200 try.sample.test try #another comment
6216.58.223.238 google.com
6216.58.223.238 google.com
7
7
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
382 @ln -sf $(REDIS_SERVER_NAME) $(INSTALL_BIN)/$(REDIS_SENTINEL_NAME)
382 @ln -sf $(REDIS_SERVER_NAME) $(INSTALL_BIN)/$(REDIS_SENTINEL_NAME)
383
383
384uninstall:
384uninstall:
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');
108
108
109$ending = 2 > 3 ? "yep" : "nah";
109$ending = 2 > 3 ? "yep" : "nah";
110
110
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
5Nuitka<0.6.8.4
5Nuitka<0.6.8.4
6wxPython>=1.0, <=2.1
6wxPython>=1.0, <=2.1
7
7
8−#this is another comment
8+#this is another comment
tests/syntax-tests/source/YAML/example.yaml+1−1
@@ -31,4 +31,4 @@ emails:
31 - bob@example.com
31 - bob@example.com
32 - bill@example.com
32 - bill@example.com
33 supervisors:
33 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.)
317..
317..
318
318
319 So this block is not "lost",
319 So this block is not "lost",
320− despite its indentation.
320+ despite its indentation.