mirror of https://github.com/sharkdp/bat.git
Respect --detect-color-scheme flag when listing themes
This commit is contained in:
parent
4409c56754
commit
4e59d3d6c3
|
@ -393,7 +393,16 @@ impl App {
|
||||||
.matches
|
.matches
|
||||||
.get_one::<String>("theme-light")
|
.get_one::<String>("theme-light")
|
||||||
.map(|t| ThemeRequest::from_str(t).unwrap());
|
.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
|
.matches
|
||||||
.get_one::<String>("detect-color-scheme")
|
.get_one::<String>("detect-color-scheme")
|
||||||
.map(|s| s.as_str())
|
.map(|s| s.as_str())
|
||||||
|
@ -402,12 +411,6 @@ impl App {
|
||||||
Some("never") => DetectColorScheme::Never,
|
Some("never") => DetectColorScheme::Never,
|
||||||
Some("always") => DetectColorScheme::Always,
|
Some("always") => DetectColorScheme::Always,
|
||||||
_ => unreachable!("other values for --detect-color-scheme are not allowed"),
|
_ => unreachable!("other values for --detect-color-scheme are not allowed"),
|
||||||
};
|
|
||||||
ThemeOptions {
|
|
||||||
theme,
|
|
||||||
theme_dark,
|
|
||||||
theme_light,
|
|
||||||
detect_color_scheme,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@ use std::io::{BufReader, Write};
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::process;
|
use std::process;
|
||||||
|
|
||||||
|
use bat::theme::DetectColorScheme;
|
||||||
use nu_ansi_term::Color::Green;
|
use nu_ansi_term::Color::Green;
|
||||||
use nu_ansi_term::Style;
|
use nu_ansi_term::Style;
|
||||||
|
|
||||||
|
@ -188,7 +189,12 @@ fn theme_preview_file<'a>() -> Input<'a> {
|
||||||
Input::from_reader(Box::new(BufReader::new(THEME_PREVIEW_DATA)))
|
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 assets = assets_from_cache_or_binary(cfg.use_custom_assets, cache_dir)?;
|
||||||
let mut config = cfg.clone();
|
let mut config = cfg.clone();
|
||||||
let mut style = HashSet::new();
|
let mut style = HashSet::new();
|
||||||
|
@ -200,8 +206,8 @@ pub fn list_themes(cfg: &Config, config_dir: &Path, cache_dir: &Path) -> Result<
|
||||||
let mut stdout = stdout.lock();
|
let mut stdout = stdout.lock();
|
||||||
|
|
||||||
if config.colored_output {
|
if config.colored_output {
|
||||||
use theme::{color_scheme, default_theme, ColorScheme, DetectColorScheme};
|
use theme::{color_scheme, default_theme, ColorScheme};
|
||||||
let default_theme = default_theme(color_scheme(DetectColorScheme::Auto));
|
let default_theme = default_theme(color_scheme(detect_color_scheme));
|
||||||
for theme in assets.themes() {
|
for theme in assets.themes() {
|
||||||
let default_theme_info = if default_theme == theme {
|
let default_theme_info = if default_theme == theme {
|
||||||
" (default)"
|
" (default)"
|
||||||
|
@ -374,7 +380,7 @@ fn run() -> Result<bool> {
|
||||||
};
|
};
|
||||||
run_controller(inputs, &plain_config, cache_dir)
|
run_controller(inputs, &plain_config, cache_dir)
|
||||||
} else if app.matches.get_flag("list-themes") {
|
} 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)
|
Ok(true)
|
||||||
} else if app.matches.get_flag("config-file") {
|
} else if app.matches.get_flag("config-file") {
|
||||||
println!("{}", config_file().to_string_lossy());
|
println!("{}", config_file().to_string_lossy());
|
||||||
|
|
|
@ -274,19 +274,18 @@ fn squeeze_limit_line_numbers() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn list_themes() {
|
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)";
|
let default_theme_chunk = "Monokai Extended\x1B[0m (default)";
|
||||||
|
let default_light_theme_chunk = "Monokai Extended Light\x1B[0m (default light)";
|
||||||
|
|
||||||
bat()
|
bat()
|
||||||
.arg("--color=always")
|
.arg("--color=always")
|
||||||
|
.arg("--detect-color-scheme=never")
|
||||||
.arg("--list-themes")
|
.arg("--list-themes")
|
||||||
.assert()
|
.assert()
|
||||||
.success()
|
.success()
|
||||||
.stdout(predicate::str::contains("DarkNeon").normalize())
|
.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())
|
||||||
.stdout(predicate::str::contains("Output the square of a number.").normalize());
|
.stdout(predicate::str::contains("Output the square of a number.").normalize());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue