use std::collections::{HashMap, HashSet, VecDeque};
use std::process;
use std::result::Result;
use std::str::FromStr;
use console::Term;
use structopt::clap;
use crate::bat_utils::assets::HighlightingAssets;
use crate::bat_utils::output::PagingMode;
use crate::cli;
use crate::config;
use crate::env;
use crate::errors::*;
use crate::features;
use crate::git_config::{GitConfig, GitConfigEntry, GitRemoteRepo};
use crate::options::option_value::{OptionValue, ProvenancedOptionValue};
use crate::options::theme;
macro_rules! set_options {
([$( $field_ident:ident ),* ],
$opt:expr, $builtin_features:expr, $git_config:expr, $arg_matches:expr, $expected_option_name_map:expr, $check_names:expr) => {
let mut option_names = HashSet::new();
$(
let kebab_case_field_name = stringify!($field_ident).replace("_", "-");
let option_name = $expected_option_name_map[kebab_case_field_name.as_str()];
if !$crate::config::user_supplied_option(&option_name, $arg_matches) {
if let Some(value) = $crate::options::get::get_option_value(
option_name,
&$builtin_features,
$opt,
$git_config
) {
$opt.$field_ident = value;
}
}
if $check_names {
option_names.insert(option_name);
}
)*
if $check_names {
option_names.extend(&[
"24-bit-color",
"diff-highlight", // Does not exist as a flag on config
"diff-so-fancy", // Does not exist as a flag on config
"features", // Processed differently
// Set prior to the rest
"no-gitconfig",
"dark",
"light",
"syntax-theme",
]);
let expected_option_names: HashSet<_> = $expected_option_name_map.values().cloned().collect();
if option_names != expected_option_names {
$crate::config::delta_unreachable(
&format!("Error processing options.\nUnhandled names: {:?}\nInvalid names: {:?}.\n",
&expected_option_names - &option_names,
&option_names - &expected_option_names));
}
}
}
}
pub fn set_options(
opt: &mut cli::Opt,
git_config: &mut Option<GitConfig>,
arg_matches: &clap::ArgMatches,
assets: HighlightingAssets,
) {
if let Some(git_config) = git_config {
if opt.no_gitconfig {
git_config.enabled = false;
}
set_git_config_entries(opt, git_config);
}
opt.navigate = opt.navigate || env::get_boolean_env_var("DELTA_NAVIGATE");
let option_names = cli::Opt::get_option_names();
// Set features
let mut builtin_features = features::make_builtin_features();
// --color-only is used for interactive.diffFilter (git add -p) and side-by-side cannot be used
// there (does not emit lines in 1-1 correspondence with raw git output). See #274.
if config::user_supplied_option("color-only", arg_matches) {
builtin_features.remove("side-by-side");
}
let features = gather_features(opt, &builtin_features, git_config);
opt.features = features.join(" ");
set_widths(opt, git_config, arg_matches, &option_names);
// Set light, dark, and syntax-theme.
set_true_color(opt);
set__light__dark__syntax_theme__options(opt, git_config, arg_matches, &option_names);
theme::set__is_light_mode__syntax_theme__syntax_set(opt, assets);
// HACK: make minus-line styles have syntax-highlighting iff side-by-side.
if features.contains(&"side-by-side".to_string()) {
let prefix = "normal ";
if !config::user_supplied_option("minus-style", arg_matches)
&& opt.minus_style.starts_with(prefix)
{
opt.minus_style = format!("syntax {}", &opt.minus_style[prefix.len()..]);
}
if !config::user_supplied_option("minus-emph-style", arg_matches)
&& opt.minus_emph_style.starts_with