From 7d37325c19cc08b6d7d1fe5e3f87a3d93a85b860 Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Sat, 29 Nov 2025 17:32:49 +0200 Subject: [PATCH] Fix to not show style decorations in auto mode when piping --- CHANGELOG.md | 1 + src/bin/bat/app.rs | 3 +-- tests/integration_tests.rs | 13 +++---------- 3 files changed, 5 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 24b0e636..80d9c492 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ - Fix hang when using `--list-themes` with an explicit pager, see #3457 (@abhinavcool42) - Fix negative values of N not being parsed in line ranges without `=` flag value separator, see #3442 (@lmmx) - Fix broken Docker syntax preventing use of custom assets, see #3476 (@keith-hall) +- Fix decorations being applied unexpectedly when piping, breaking cat compatibility. See #3496 (@keith-hall) ## Other - Improve README documentation on pager options passed to less, see #3443 (@injust) diff --git a/src/bin/bat/app.rs b/src/bin/bat/app.rs index 4c0ade1e..8f9cc871 100644 --- a/src/bin/bat/app.rs +++ b/src/bin/bat/app.rs @@ -384,8 +384,7 @@ impl App { .map(|s| s.as_str()) == Some("always") || self.matches.get_flag("force-colorization") - || self.matches.get_flag("number") - || self.matches.contains_id("style") && !style_components.plain()), + || self.matches.get_flag("number")), tab_width: self .matches .get_one::("tabs") diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs index 5dc35d6e..d5ce3d03 100644 --- a/tests/integration_tests.rs +++ b/tests/integration_tests.rs @@ -415,7 +415,7 @@ fn piped_output_with_line_numbers_style_flag() { .write_stdin("hello\nworld\n") .assert() .success() - .stdout(" 1 hello\n 2 world\n"); + .stdout("hello\nworld\n"); } #[test] @@ -426,15 +426,7 @@ fn piped_output_with_line_numbers_with_header_grid_style_flag() { .write_stdin("hello\nworld\n") .assert() .success() - .stdout( - "─────┬────────────────────────────────────────────────────────────────────────── - │ STDIN -─────┼────────────────────────────────────────────────────────────────────────── - 1 │ hello - 2 │ world -─────┴────────────────────────────────────────────────────────────────────────── -", - ); + .stdout("hello\nworld\n"); } #[test] @@ -452,6 +444,7 @@ fn piped_output_with_auto_style() { fn piped_output_with_default_style_flag() { bat() .arg("--style=default") + .arg("--decorations=always") .write_stdin("hello\nworld\n") .assert() .success()