mirror of
https://github.com/sharkdp/bat
synced 2026-07-30 18:11:44 +00:00
Merge color scheme options into theme / BAT_THEME
This commit is contained in:
+5
-20
@@ -9,7 +9,7 @@ use crate::{
|
||||
config::{get_args_from_config_file, get_args_from_env_opts_var, get_args_from_env_vars},
|
||||
};
|
||||
use bat::style::StyleComponentList;
|
||||
use bat::theme::{theme, ColorSchemePreference, DetectColorScheme, ThemeOptions, ThemeRequest};
|
||||
use bat::theme::{theme, ThemeName, ThemeOptions, ThemePreference};
|
||||
use bat::StripAnsiMode;
|
||||
use clap::ArgMatches;
|
||||
|
||||
@@ -418,35 +418,20 @@ impl App {
|
||||
let theme = self
|
||||
.matches
|
||||
.get_one::<String>("theme")
|
||||
.map(|t| ThemeRequest::from_str(t).unwrap());
|
||||
.map(|t| ThemePreference::from_str(t).unwrap())
|
||||
.unwrap_or_default();
|
||||
let theme_dark = self
|
||||
.matches
|
||||
.get_one::<String>("theme-dark")
|
||||
.map(|t| ThemeRequest::from_str(t).unwrap());
|
||||
.map(|t| ThemeName::from_str(t).unwrap());
|
||||
let theme_light = self
|
||||
.matches
|
||||
.get_one::<String>("theme-light")
|
||||
.map(|t| ThemeRequest::from_str(t).unwrap());
|
||||
.map(|t| ThemeName::from_str(t).unwrap());
|
||||
ThemeOptions {
|
||||
theme,
|
||||
theme_dark,
|
||||
theme_light,
|
||||
color_scheme: self.color_scheme_preference(),
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn color_scheme_preference(&self) -> ColorSchemePreference {
|
||||
match self
|
||||
.matches
|
||||
.get_one::<String>("color-scheme")
|
||||
.map(|s| s.as_str())
|
||||
{
|
||||
Some("auto") => ColorSchemePreference::Auto(DetectColorScheme::Auto),
|
||||
Some("auto:always") => ColorSchemePreference::Auto(DetectColorScheme::Always),
|
||||
Some("dark") => ColorSchemePreference::Dark,
|
||||
Some("light") => ColorSchemePreference::Light,
|
||||
Some("system") => ColorSchemePreference::System,
|
||||
_ => unreachable!("other values for --color-scheme are not allowed"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -383,32 +383,6 @@ pub fn build_app(interactive_output: bool) -> Command {
|
||||
BAT_THEME=\"...\").",
|
||||
),
|
||||
)
|
||||
.arg(
|
||||
Arg::new("color-scheme")
|
||||
.long("color-scheme")
|
||||
.overrides_with("color-scheme")
|
||||
.value_name("scheme")
|
||||
.value_parser(["auto", "auto:always", "dark", "light", "system"])
|
||||
.default_value("auto")
|
||||
.hide_default_value(true)
|
||||
.help("Specify whether to choose a dark or light theme.")
|
||||
.long_help(
|
||||
"Specify whether to choose a dark or light syntax highlighting theme. \
|
||||
Use '--theme-light' and '--theme-dark' (or the environment variables \
|
||||
BAT_THEME_LIGHT and BAT_THEME_DARK) to configure which themes are picked. \
|
||||
You may also use '--theme' to set a theme that is used regardless of this choice.\n\n\
|
||||
Possible values:\n\
|
||||
* auto (default):\n \
|
||||
Query the terminals for its color scheme if the output is not redirected. \
|
||||
This is to prevent race conditions with pagers such as less.\n\
|
||||
* 'auto:always':\n \
|
||||
Always query the terminal for its color scheme, \
|
||||
regardless of whether or not the output is redirected.\n\
|
||||
* dark: Use a dark syntax highlighting theme.\n\
|
||||
* light: Use a light syntax highlighting theme.\n\
|
||||
* system: Query the OS for its color scheme. Only works on macOS.\n\
|
||||
"),
|
||||
)
|
||||
.arg(
|
||||
Arg::new("theme-light")
|
||||
.long("theme-light")
|
||||
|
||||
+1
-1
@@ -384,7 +384,7 @@ fn run() -> Result<bool> {
|
||||
&config,
|
||||
config_dir,
|
||||
cache_dir,
|
||||
app.color_scheme_preference(),
|
||||
ColorSchemePreference::default(),
|
||||
)?;
|
||||
Ok(true)
|
||||
} else if app.matches.get_flag("config-file") {
|
||||
|
||||
Reference in New Issue
Block a user