diff options
author | Stéphane Blondon <stephane.blondon@gmail.com> | 2024-04-14 17:17:58 +0200 |
---|---|---|
committer | Martin Nordholts <enselic@gmail.com> | 2024-04-19 11:44:47 +0200 |
commit | 23ec43316708b51f96ac3f9b5fc486494205236b (patch) | |
tree | 2da1a7545fe0db31dc6df94d301b2c990ca6d4e5 | |
parent | 9eaed3e3f088d210467727201b0fb2b4e1e8f763 (diff) |
display which theme is the default one in basic output
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rw-r--r-- | src/bin/bat/main.rs | 9 | ||||
-rw-r--r-- | tests/integration_tests.rs | 19 |
3 files changed, 26 insertions, 3 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 4fa912c7..28e56e34 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,6 +34,7 @@ - Relax syntax mapping rule restrictions to allow brace expansion #2865 (@cyqsimon) - Apply clippy fixes #2864 (@cyqsimon) - Faster startup by offloading glob matcher building to a worker thread #2868 (@cyqsimon) +- Display which theme is the default one in basic output (no colors), see #2937 (@sblondon) - Display which theme is the default one in colored output, see #2838 (@sblondon) ## Syntaxes diff --git a/src/bin/bat/main.rs b/src/bin/bat/main.rs index 78202539..027f4ec4 100644 --- a/src/bin/bat/main.rs +++ b/src/bin/bat/main.rs @@ -200,8 +200,8 @@ pub fn list_themes(cfg: &Config, config_dir: &Path, cache_dir: &Path) -> Result< let stdout = io::stdout(); let mut stdout = stdout.lock(); + let default_theme = HighlightingAssets::default_theme(); if config.colored_output { - let default_theme = HighlightingAssets::default_theme(); for theme in assets.themes() { let default_theme_info = if default_theme == theme { " (default)" @@ -230,7 +230,12 @@ pub fn list_themes(cfg: &Config, config_dir: &Path, cache_dir: &Path) -> Result< )?; } else { for theme in assets.themes() { - writeln!(stdout, "{theme}")?; + let default_theme_info = if default_theme == theme { + " (default)" + } else { + "" + }; + writeln!(stdout, "{theme}{default_theme_info}")?; } } diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs index 9de8236a..0285ac26 100644 --- a/tests/integration_tests.rs +++ b/tests/integration_tests.rs @@ -273,7 +273,7 @@ fn squeeze_limit_line_numbers() { } #[test] -fn list_themes() { +fn list_themes_with_colors() { #[cfg(target_os = "macos")] let default_theme_chunk = "Monokai Extended Light\x1B[0m (default)"; @@ -291,6 +291,23 @@ fn list_themes() { } #[test] +fn list_themes_without_colors() { + #[cfg(target_os = "macos")] + let default_theme_chunk = "Monokai Extended Light (default)"; + + #[cfg(not(target_os = "macos"))] + let default_theme_chunk = "Monokai Extended (default)"; + + bat() + .arg("--color=never") + .arg("--list-themes") + .assert() + .success() + .stdout(predicate::str::contains("DarkNeon").normalize()) + .stdout(predicate::str::contains(default_theme_chunk).normalize()); +} + +#[test] #[cfg_attr(any(not(feature = "git"), target_os = "windows"), ignore)] fn short_help() { test_help("-h", "../doc/short-help.txt"); |