1
0
mirror of https://github.com/sharkdp/bat.git synced 2025-02-15 09:28:26 +00:00

Merge pull request #3189 from einfachIrgendwer0815/fix/list_themes_2

Fix: Don't output default theme info to piped stdout
This commit is contained in:
Keith Hall 2025-01-27 21:59:18 +02:00 committed by GitHub
commit b14fb9db24
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 11 additions and 7 deletions

View File

@ -3,7 +3,8 @@
## Features ## Features
## Bugfixes ## Bugfixes
* Fix `BAT_THEME_DARK` and `BAT_THEME_LIGHT` being ignored, see issue #3171 and PR #3168 (@bash) - Fix `BAT_THEME_DARK` and `BAT_THEME_LIGHT` being ignored, see issue #3171 and PR #3168 (@bash)
- Prevent `--list-themes` from outputting default theme info to stdout when it is piped, see #3189 (@einfachIrgendwer0815)
## Other ## Other

View File

@ -210,7 +210,7 @@ pub fn list_themes(
let default_theme_name = default_theme(color_scheme(detect_color_scheme).unwrap_or_default()); let default_theme_name = default_theme(color_scheme(detect_color_scheme).unwrap_or_default());
for theme in assets.themes() { for theme in assets.themes() {
let default_theme_info = if !config.loop_through && default_theme_name == theme { let default_theme_info = if default_theme_name == theme {
" (default)" " (default)"
} else if default_theme(ColorScheme::Dark) == theme { } else if default_theme(ColorScheme::Dark) == theme {
" (default dark)" " (default dark)"
@ -231,6 +231,8 @@ pub fn list_themes(
.run(vec![theme_preview_file()], None) .run(vec![theme_preview_file()], None)
.ok(); .ok();
writeln!(stdout)?; writeln!(stdout)?;
} else if config.loop_through {
writeln!(stdout, "{theme}")?;
} else { } else {
writeln!(stdout, "{theme}{default_theme_info}")?; writeln!(stdout, "{theme}{default_theme_info}")?;
} }

View File

@ -305,11 +305,12 @@ fn list_themes_without_colors() {
#[test] #[test]
fn list_themes_to_piped_output() { fn list_themes_to_piped_output() {
bat() bat().arg("--list-themes").assert().success().stdout(
.arg("--list-themes") predicate::str::contains("(default)")
.assert() .not()
.success() .and(predicate::str::contains("(default light)").not())
.stdout(predicate::str::contains("(default)").not()); .and(predicate::str::contains("(default dark)").not()),
);
} }
#[test] #[test]