summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsblondon <stephane.blondon@gmail.com>2024-04-14 15:54:52 +0200
committerGitHub <noreply@github.com>2024-04-14 15:54:52 +0200
commitd5bd4aa93fe3ff8643c0dd0cdb8700e8430d7931 (patch)
treef21f6e407fc457824a87d31cb960c9d96d4b0347
parent66b70dd8ed1b673605d02408ac258cd34e19991d (diff)
display which theme is the default one in colored output (#2838)
-rw-r--r--CHANGELOG.md1
-rw-r--r--src/bin/bat/main.rs12
-rw-r--r--tests/integration_tests.rs18
3 files changed, 29 insertions, 2 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index c7ebdc55..3444127e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -33,6 +33,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 colored output, see #2838 (@sblondon)
## Syntaxes
diff --git a/src/bin/bat/main.rs b/src/bin/bat/main.rs
index 615f1114..78202539 100644
--- a/src/bin/bat/main.rs
+++ b/src/bin/bat/main.rs
@@ -30,6 +30,7 @@ use directories::PROJECT_DIRS;
use globset::GlobMatcher;
use bat::{
+ assets::HighlightingAssets,
config::Config,
controller::Controller,
error::*,
@@ -200,11 +201,18 @@ pub fn list_themes(cfg: &Config, config_dir: &Path, cache_dir: &Path) -> Result<
let mut stdout = stdout.lock();
if config.colored_output {
+ let default_theme = HighlightingAssets::default_theme();
for theme in assets.themes() {
+ let default_theme_info = if default_theme == theme {
+ " (default)"
+ } else {
+ ""
+ };
writeln!(
stdout,
- "Theme: {}\n",
- Style::new().bold().paint(theme.to_string())
+ "Theme: {}{}\n",
+ Style::new().bold().paint(theme.to_string()),
+ default_theme_info
)?;
config.theme = theme.to_string();
Controller::new(&config, &assets)
diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs
index d6523366..9de8236a 100644
--- a/tests/integration_tests.rs
+++ b/tests/integration_tests.rs
@@ -273,6 +273,24 @@ fn squeeze_limit_line_numbers() {
}
#[test]
+fn list_themes() {
+ #[cfg(target_os = "macos")]
+ let default_theme_chunk = "Monokai Extended Light\x1B[0m (default)";
+
+ #[cfg(not(target_os = "macos"))]
+ let default_theme_chunk = "Monokai Extended\x1B[0m (default)";
+
+ bat()
+ .arg("--color=always")
+ .arg("--list-themes")
+ .assert()
+ .success()
+ .stdout(predicate::str::contains("DarkNeon").normalize())
+ .stdout(predicate::str::contains(default_theme_chunk).normalize())
+ .stdout(predicate::str::contains("Output the square of a number.").normalize());
+}
+
+#[test]
#[cfg_attr(any(not(feature = "git"), target_os = "windows"), ignore)]
fn short_help() {
test_help("-h", "../doc/short-help.txt");