From 0603f0b844707d3f9de7a9a7f110fd5a4f2743a9 Mon Sep 17 00:00:00 2001 From: einfachIrgendwer0815 <85333734+einfachIrgendwer0815@users.noreply.github.com> Date: Sun, 25 Aug 2024 10:54:46 +0200 Subject: [PATCH 1/2] Don't output default theme info to piped stdout --- src/bin/bat/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bin/bat/main.rs b/src/bin/bat/main.rs index 4528a60b..3b74ec75 100644 --- a/src/bin/bat/main.rs +++ b/src/bin/bat/main.rs @@ -202,7 +202,7 @@ pub fn list_themes(cfg: &Config, config_dir: &Path, cache_dir: &Path) -> Result< let default_theme = HighlightingAssets::default_theme(); for theme in assets.themes() { - let default_theme_info = if default_theme == theme { + let default_theme_info = if !config.loop_through && default_theme == theme { " (default)" } else { "" From 5be9d195003c00754885b2e3bb00cf13b6e707d2 Mon Sep 17 00:00:00 2001 From: einfachIrgendwer0815 <85333734+einfachIrgendwer0815@users.noreply.github.com> Date: Sun, 25 Aug 2024 11:07:29 +0200 Subject: [PATCH 2/2] Reinforce tests for `--list-themes` --- tests/integration_tests.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs index 8df4327c..c083a941 100644 --- a/tests/integration_tests.rs +++ b/tests/integration_tests.rs @@ -300,6 +300,7 @@ fn list_themes_without_colors() { bat() .arg("--color=never") + .arg("--decorations=always") // trick bat into setting `Config::loop_through` to false .arg("--list-themes") .assert() .success() @@ -307,6 +308,15 @@ fn list_themes_without_colors() { .stdout(predicate::str::contains(default_theme_chunk).normalize()); } +#[test] +fn list_themes_to_piped_output() { + bat() + .arg("--list-themes") + .assert() + .success() + .stdout(predicate::str::contains("(default)").not()); +} + #[test] #[cfg_attr(any(not(feature = "git"), target_os = "windows"), ignore)] fn short_help() {