diff --git a/src/bin/bat/app.rs b/src/bin/bat/app.rs index 9a5621ecc0..6a51171a6e 100644 --- a/src/bin/bat/app.rs +++ b/src/bin/bat/app.rs @@ -393,7 +393,16 @@ impl App { .matches .get_one::("theme-light") .map(|t| ThemeRequest::from_str(t).unwrap()); - let detect_color_scheme = match self + ThemeOptions { + theme, + theme_dark, + theme_light, + detect_color_scheme: self.detect_color_scheme(), + } + } + + pub(crate) fn detect_color_scheme(&self) -> DetectColorScheme { + match self .matches .get_one::("detect-color-scheme") .map(|s| s.as_str()) @@ -402,12 +411,6 @@ impl App { Some("never") => DetectColorScheme::Never, Some("always") => DetectColorScheme::Always, _ => unreachable!("other values for --detect-color-scheme are not allowed"), - }; - ThemeOptions { - theme, - theme_dark, - theme_light, - detect_color_scheme, } } } diff --git a/src/bin/bat/main.rs b/src/bin/bat/main.rs index 4dfb812448..95493a6d2a 100644 --- a/src/bin/bat/main.rs +++ b/src/bin/bat/main.rs @@ -189,7 +189,12 @@ fn theme_preview_file<'a>() -> Input<'a> { Input::from_reader(Box::new(BufReader::new(THEME_PREVIEW_DATA))) } -pub fn list_themes(cfg: &Config, config_dir: &Path, cache_dir: &Path) -> Result<()> { +pub fn list_themes( + cfg: &Config, + config_dir: &Path, + cache_dir: &Path, + detect_color_scheme: DetectColorScheme, +) -> Result<()> { let assets = assets_from_cache_or_binary(cfg.use_custom_assets, cache_dir)?; let mut config = cfg.clone(); let mut style = HashSet::new(); @@ -200,7 +205,7 @@ 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_name = default_theme(color_scheme(DetectColorScheme::Auto)); + let default_theme_name = default_theme(color_scheme(detect_color_scheme)); for theme in assets.themes() { let default_theme_info = if default_theme_name == theme { " (default)" @@ -375,7 +380,7 @@ fn run() -> Result { }; run_controller(inputs, &plain_config, cache_dir) } else if app.matches.get_flag("list-themes") { - list_themes(&config, config_dir, cache_dir)?; + list_themes(&config, config_dir, cache_dir, app.detect_color_scheme())?; Ok(true) } else if app.matches.get_flag("config-file") { println!("{}", config_file().to_string_lossy()); diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs index bf303fe807..66eaef4166 100644 --- a/tests/integration_tests.rs +++ b/tests/integration_tests.rs @@ -274,37 +274,35 @@ fn squeeze_limit_line_numbers() { #[test] fn list_themes_with_colors() { - #[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)"; + let default_light_theme_chunk = "Monokai Extended Light\x1B[0m (default light)"; bat() .arg("--color=always") + .arg("--detect-color-scheme=never") .arg("--list-themes") .assert() .success() .stdout(predicate::str::contains("DarkNeon").normalize()) .stdout(predicate::str::contains(default_theme_chunk).normalize()) + .stdout(predicate::str::contains(default_light_theme_chunk).normalize()) .stdout(predicate::str::contains("Output the square of a number.").normalize()); } #[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)"; + let default_light_theme_chunk = "Monokai Extended Light (default light)"; bat() .arg("--color=never") + .arg("--detect-color-scheme=never") .arg("--list-themes") .assert() .success() .stdout(predicate::str::contains("DarkNeon").normalize()) - .stdout(predicate::str::contains(default_theme_chunk).normalize()); + .stdout(predicate::str::contains(default_theme_chunk).normalize()) + .stdout(predicate::str::contains(default_light_theme_chunk).normalize()); } #[test]