1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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);
}
}
}
}
|