diff options
author | Dan Davison <dandavison7@gmail.com> | 2020-06-29 18:18:34 -0400 |
---|---|---|
committer | Dan Davison <dandavison7@gmail.com> | 2020-06-30 08:00:30 -0400 |
commit | 859ae8971f3011f3dd3c7e0d35cc4834d6940668 (patch) | |
tree | 409dc8fe6a8a7e6501a865429d7f91e0be54fea5 /src/options | |
parent | 9349373cd8f08cb8639535d4c580d7b98bc29843 (diff) |
Call preprocess
Diffstat (limited to 'src/options')
-rw-r--r-- | src/options/mod.rs | 1 | ||||
-rw-r--r-- | src/options/preprocess.rs | 56 |
2 files changed, 57 insertions, 0 deletions
diff --git a/src/options/mod.rs b/src/options/mod.rs index d0540f67..7ccd4b90 100644 --- a/src/options/mod.rs +++ b/src/options/mod.rs @@ -1,4 +1,5 @@ pub mod get; pub mod option_value; +pub mod preprocess; pub mod rewrite; pub mod set; diff --git a/src/options/preprocess.rs b/src/options/preprocess.rs new file mode 100644 index 00000000..818470f1 --- /dev/null +++ b/src/options/preprocess.rs @@ -0,0 +1,56 @@ +use std::process; + +use crate::bat::assets::HighlightingAssets; +use crate::cli; +use crate::env; +use crate::syntax_theme; + +pub fn preprocess_options(opt: &mut cli::Opt, assets: HighlightingAssets) { + _check_validity(&opt, &assets); + let syntax_theme_name_from_bat_theme = env::get_env_var("BAT_THEME"); + let (is_light_mode, syntax_theme_name) = syntax_theme::get_is_light_mode_and_theme_name( + opt.syntax_theme.as_ref(), + syntax_theme_name_from_bat_theme.as_ref(), + opt.light, + &assets.theme_set, + ); + opt.computed.is_light_mode = is_light_mode; + + opt.computed.syntax_theme = + if syntax_theme::is_no_syntax_highlighting_theme_name(&syntax_theme_name) { + None + } else { + Some(assets.theme_set.themes[&syntax_theme_name].clone()) + }; + opt.computed.syntax_set = assets.syntax_set; +} + +fn _check_validity(opt: &cli::Opt, assets: &HighlightingAssets) { + if opt.light && opt.dark { + eprintln!("--light and --dark cannot be used together."); + process::exit(1); + } + if let Some(ref syntax_theme) = opt.syntax_theme { + if !syntax_theme::is_no_syntax_highlighting_theme_name(&syntax_theme) { + if !assets.theme_set.themes.contains_key(syntax_theme.as_str()) { + return; + } + let is_light_syntax_theme = syntax_theme::is_light_theme(&syntax_theme); + if is_light_syntax_theme && opt.dark { + eprintln!( + "{} is a light syntax theme, but you supplied --dark. \ + If you use --syntax-theme, you do not need to supply --light or --dark.", + syntax_theme + ); + process::exit(1); + } else if !is_light_syntax_theme && opt.light { + eprintln!( + "{} is a dark syntax theme, but you supplied --light. \ + If you use --syntax-theme, you do not need to supply --light or --dark.", + syntax_theme + ); + process::exit(1); + } + } + } +} |