diff options
author | Dan Davison <dandavison7@gmail.com> | 2020-06-20 14:03:32 -0400 |
---|---|---|
committer | Dan Davison <dandavison7@gmail.com> | 2020-06-20 14:12:20 -0400 |
commit | db027a4469138610acd6328f4525bf23ebdddcbe (patch) | |
tree | 33716d0ad48f386563aa1a36a0cd1b80cd36b123 | |
parent | db9c55e8f7c1f567276943b37686f5ac2153a31d (diff) |
s/preset/feature/
-rw-r--r-- | src/cli.rs | 34 | ||||
-rw-r--r-- | src/features/diff_highlight.rs (renamed from src/presets/diff_highlight.rs) | 10 | ||||
-rw-r--r-- | src/features/diff_so_fancy.rs (renamed from src/presets/diff_so_fancy.rs) | 12 | ||||
-rw-r--r-- | src/features/mod.rs (renamed from src/presets/mod.rs) | 90 | ||||
-rw-r--r-- | src/main.rs | 2 | ||||
-rw-r--r-- | src/rewrite_options.rs | 2 | ||||
-rw-r--r-- | src/set_options.rs | 52 |
7 files changed, 101 insertions, 101 deletions
@@ -24,35 +24,35 @@ is number = true zero-style = dim syntax -PRESETS +FEATURES ------- -A preset is a named collection of delta options in ~/.gitconfig. An example is: +A feature is a named collection of delta options in ~/.gitconfig. An example is: -[delta \"my-delta-preset\"] +[delta \"my-delta-feature\"] syntax-theme = Dracula plus-style = bold syntax \"#002800\" ... To activate those options, you would use: -delta --presets my-delta-preset +delta --features my-delta-feature or in ~/.gitconfig [delta] - presets = my-delta-preset + features = my-delta-feature -A single preset name may not contain whitespace. You can activate multiple presets: +A single feature name may not contain whitespace. You can activate multiple features: [delta] - presets = my-highlight-styles-colors-preset my-line-number-styles-preset + features = my-highlight-styles-colors-feature my-line-number-styles-feature -If more than one preset sets the same option, the last one wins. +If more than one feature sets the same option, the last one wins. -There are two built-in presets: +There are two built-in features: ---presets diff-highlight (https://github.com/git/git/tree/master/contrib/diff-highlight) ---presets diff-so-fancy (https://github.com/so-fancy/diff-so-fancy) +--features diff-highlight (https://github.com/git/git/tree/master/contrib/diff-highlight) +--features diff-so-fancy (https://github.com/so-fancy/diff-so-fancy) STYLES ------ @@ -169,12 +169,12 @@ https://github.com/dandavison/delta/issues. " )] pub struct Opt { - #[structopt(long = "presets", env = "DELTA_PRESET")] - /// Name of delta presets to use (space-separated). A preset is a named collection of delta - /// options in ~/.gitconfig. The preset names can also be set using an environment variable - /// named DELTA_PRESETS. Two built-in presets are available: 'diff-highlight' and - /// 'diff-so-fancy'. See PRESETS section. - pub presets: Option<String>, + #[structopt(long = "features", env = "DELTA_FEATURE")] + /// Name of delta features to use (space-separated). A feature is a named collection of delta + /// options in ~/.gitconfig. The feature names can also be set using an environment variable + /// named DELTA_FEATURES. Two built-in features are available: 'diff-highlight' and + /// 'diff-so-fancy'. See FEATURES section. + pub features: Option<String>, #[structopt(long = "syntax-theme", env = "BAT_THEME")] /// The code syntax-highlighting theme to use. Use --list-syntax-themes to demo available diff --git a/src/presets/diff_highlight.rs b/src/features/diff_highlight.rs index 190b189d..4bda3fa9 100644 --- a/src/presets/diff_highlight.rs +++ b/src/features/diff_highlight.rs @@ -1,11 +1,11 @@ -use crate::presets::PresetValueFunction; +use crate::features::FeatureValueFunction; -pub fn make_preset() -> Vec<(String, PresetValueFunction)> { - _make_preset(false) +pub fn make_feature() -> Vec<(String, FeatureValueFunction)> { + _make_feature(false) } -pub fn _make_preset<'a>(bold: bool) -> Vec<(String, PresetValueFunction)> { - builtin_preset!([ +pub fn _make_feature(bold: bool) -> Vec<(String, FeatureValueFunction)> { + builtin_feature!([ ( "minus-style", String, diff --git a/src/presets/diff_so_fancy.rs b/src/features/diff_so_fancy.rs index 30938d3a..fa5952db 100644 --- a/src/presets/diff_so_fancy.rs +++ b/src/features/diff_so_fancy.rs @@ -1,9 +1,9 @@ -use crate::presets::diff_highlight; -use crate::presets::PresetValueFunction; +use crate::features::diff_highlight; +use crate::features::FeatureValueFunction; -pub fn make_preset() -> Vec<(String, PresetValueFunction)> { - let mut preset = diff_highlight::_make_preset(true); - preset.extend(builtin_preset!([ +pub fn make_feature() -> Vec<(String, FeatureValueFunction)> { + let mut feature = diff_highlight::_make_feature(true); + feature.extend(builtin_feature!([ ( "minus-emph-style", String, @@ -53,5 +53,5 @@ pub fn make_preset() -> Vec<(String, PresetValueFunction)> { _opt => "magenta box" ) ])); - preset + feature } diff --git a/src/presets/mod.rs b/src/features/mod.rs index 7daa29a1..ac230d45 100644 --- a/src/presets/mod.rs +++ b/src/features/mod.rs @@ -3,7 +3,7 @@ use std::collections::HashMap; use crate::cli; use crate::git_config::GitConfig; -/// A preset is a named set of command line (option, value) pairs, supplied in a git config file. +/// A feature is a named set of command line (option, value) pairs, supplied in a git config file. /// I.e. it might look like /// /// [delta "decorations"] @@ -11,12 +11,12 @@ use crate::git_config::GitConfig; /// file-style = bold 19 ul /// file-decoration-style = none /// -/// A builtin preset is a named set of command line (option, value) pairs that is built in to +/// A builtin feature is a named set of command line (option, value) pairs that is built in to /// delta. The implementation stores each value as a function, which allows the value (a) to depend /// dynamically on the value of other command line options, and (b) to be taken from git config. -pub type BuiltinPreset = HashMap<String, PresetValueFunction>; +pub type BuiltinFeature = HashMap<String, FeatureValueFunction>; -type PresetValueFunction = Box<dyn Fn(&cli::Opt, &Option<GitConfig>) -> OptionValue>; +type FeatureValueFunction = Box<dyn Fn(&cli::Opt, &Option<GitConfig>) -> OptionValue>; pub enum OptionValue { Boolean(bool), @@ -26,27 +26,27 @@ pub enum OptionValue { Int(usize), } -// Construct a 2-level hash map: (preset name) -> (option name) -> (value function). A value +// Construct a 2-level hash map: (feature name) -> (option name) -> (value function). A value // function is a function that takes an Opt struct, and a git Config struct, and returns the value // for the option. -pub fn make_builtin_presets() -> HashMap<String, BuiltinPreset> { +pub fn make_builtin_features() -> HashMap<String, BuiltinFeature> { vec![ ( "diff-highlight".to_string(), - diff_highlight::make_preset().into_iter().collect(), + diff_highlight::make_feature().into_iter().collect(), ), ( "diff-so-fancy".to_string(), - diff_so_fancy::make_preset().into_iter().collect(), + diff_so_fancy::make_feature().into_iter().collect(), ), ] .into_iter() .collect() } -/// The macro permits the values of a builtin preset to be specified as either (a) a git config +/// The macro permits the values of a builtin feature to be specified as either (a) a git config /// entry or (b) a value, which may be computed from the other command line options (cli::Opt). -macro_rules! builtin_preset { +macro_rules! builtin_feature { ([$( ($option_name:expr, $type:ty, $git_config_key:expr, $opt:ident => $value:expr) ),*]) => { vec![$( ( @@ -60,7 +60,7 @@ macro_rules! builtin_preset { _ => None, } .unwrap_or_else(|| $value.into()) - }) as PresetValueFunction + }) as FeatureValueFunction ) ),*] } @@ -201,26 +201,26 @@ mod tests { } #[test] - fn test_preset() { + fn test_feature() { let git_config_contents = b" [delta] minus-style = blue -[delta \"my-preset\"] +[delta \"my-feature\"] minus-style = green "; - let git_config_path = "delta__test_preset.gitconfig"; + let git_config_path = "delta__test_feature.gitconfig"; - // Without --presets the main section takes effect + // Without --features the main section takes effect assert_eq!( make_config(&[], Some(git_config_contents), Some(git_config_path)).minus_style, make_style("blue") ); - // With --presets the preset takes effect + // With --features the feature takes effect assert_eq!( make_config( - &["--presets", "my-preset"], + &["--features", "my-feature"], Some(git_config_contents), Some(git_config_path), ) @@ -231,22 +231,22 @@ mod tests { } #[test] - fn test_multiple_presets() { + fn test_multiple_features() { let git_config_contents = b" [delta] minus-style = blue -[delta \"my-preset-1\"] +[delta \"my-feature-1\"] minus-style = green -[delta \"my-preset-2\"] +[delta \"my-feature-2\"] minus-style = yellow "; - let git_config_path = "delta__test_multiple_presets.gitconfig"; + let git_config_path = "delta__test_multiple_features.gitconfig"; assert_eq!( make_config( - &["--presets", "my-preset-1"], + &["--features", "my-feature-1"], Some(git_config_contents), Some(git_config_path), ) @@ -256,7 +256,7 @@ mod tests { assert_eq!( make_config( - &["--presets", "my-preset-1 my-preset-2"], + &["--features", "my-feature-1 my-feature-2"], Some(git_config_contents), Some(git_config_path), ) @@ -266,7 +266,7 @@ mod tests { assert_eq!( make_config( - &["--presets", "my-preset-2 my-preset-1"], + &["--features", "my-feature-2 my-feature-1"], Some(git_config_contents), Some(git_config_path), ) @@ -278,22 +278,22 @@ mod tests { } #[test] - fn test_invalid_presets() { + fn test_invalid_features() { let git_config_contents = b" [delta] minus-style = blue -[delta \"my-preset-1\"] +[delta \"my-feature-1\"] minus-style = green -[delta \"my-preset-2\"] +[delta \"my-feature-2\"] minus-style = yellow "; - let git_config_path = "delta__test_invalid_presets.gitconfig"; + let git_config_path = "delta__test_invalid_features.gitconfig"; assert_eq!( make_config( - &["--presets", "my-preset-1"], + &["--features", "my-feature-1"], Some(git_config_contents), Some(git_config_path), ) @@ -303,7 +303,7 @@ mod tests { assert_eq!( make_config( - &["--presets", "my-preset-x"], + &["--features", "my-feature-x"], Some(git_config_contents), Some(git_config_path), ) @@ -313,7 +313,7 @@ mod tests { assert_eq!( make_config( - &["--presets", "my-preset-1 my-preset-x"], + &["--features", "my-feature-1 my-feature-x"], Some(git_config_contents), Some(git_config_path), ) @@ -323,7 +323,7 @@ mod tests { assert_eq!( make_config( - &["--presets", "my-preset-x my-preset-2 my-preset-x"], + &["--features", "my-feature-x my-feature-2 my-feature-x"], Some(git_config_contents), Some(git_config_path), ) @@ -354,7 +354,7 @@ mod tests { ); let git_config_contents = b" -[delta \"my-navigate-preset\"] +[delta \"my-navigate-feature\"] navigate = true file-modified-label = \"modified: \" "; @@ -365,7 +365,7 @@ mod tests { ); assert_eq!( make_config( - &["--presets", "my-navigate-preset"], + &["--features", "my-navigate-feature"], Some(git_config_contents), Some(git_config_path) ) @@ -376,7 +376,7 @@ mod tests { #[test] fn test_diff_highlight_defaults() { - let config = make_config(&["--presets", "diff-highlight"], None, None); + let config = make_config(&["--features", "diff-highlight"], None, None); assert_eq!(config.minus_style, make_style("red")); assert_eq!(config.minus_non_emph_style, make_style("red")); @@ -403,7 +403,7 @@ mod tests { let git_config_path = "delta__test_diff_highlight.gitconfig"; let config = make_config( - &["--presets", "diff-highlight"], + &["--features", "diff-highlight"], Some(git_config_contents), Some(git_config_path), ); @@ -421,7 +421,7 @@ mod tests { #[test] fn test_diff_so_fancy_defaults() { - let config = make_config(&["--presets", "diff-so-fancy"], None, None); + let config = make_config(&["--features", "diff-so-fancy"], None, None); assert_eq!( config.commit_style.ansi_term_style, @@ -465,7 +465,7 @@ mod tests { let git_config_path = "delta__test_diff_so_fancy.gitconfig"; let config = make_config( - &["--presets", "diff-so-fancy some-other-preset"], + &["--features", "diff-so-fancy some-other-feature"], Some(git_config_contents), Some(git_config_path), ); @@ -499,7 +499,7 @@ mod tests { } #[test] - fn test_diff_so_fancy_obeys_preset_precedence_rules() { + fn test_diff_so_fancy_obeys_feature_precedence_rules() { let git_config_contents = b" [color \"diff\"] meta = 11 @@ -514,10 +514,10 @@ mod tests { file-style = bold 19 ul file-decoration-style = none "; - let git_config_path = "delta__test_diff_so_fancy_obeys_preset_precedence_rules.gitconfig"; + let git_config_path = "delta__test_diff_so_fancy_obeys_feature_precedence_rules.gitconfig"; let config = make_config( - &["--presets", "decorations diff-so-fancy"], + &["--features", "decorations diff-so-fancy"], Some(git_config_contents), Some(git_config_path), ); @@ -533,7 +533,7 @@ mod tests { ); let config = make_config( - &["--presets", "diff-so-fancy decorations"], + &["--features", "diff-so-fancy decorations"], Some(git_config_contents), Some(git_config_path), ); @@ -590,7 +590,7 @@ mod tests { [delta] whitespace-error-style = blue reverse -[delta \"my-whitespace-error-style-preset\"] +[delta \"my-whitespace-error-style-feature\"] whitespace-error-style = green reverse "; @@ -612,10 +612,10 @@ mod tests { make_style("blue reverse") ); - // No command line argument; preset section wins + // No command line argument; feature section wins assert_eq!( make_config( - &["--presets", "my-whitespace-error-style-preset"], + &["--features", "my-whitespace-error-style-feature"], Some(git_config_contents), Some(git_config_path) ) diff --git a/src/main.rs b/src/main.rs index aa686ba1..dddd8b09 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,10 +12,10 @@ mod delta; mod draw; mod edits; mod env; +mod features; mod git_config; mod paint; mod parse; -mod presets; mod rewrite_options; mod set_options; mod style; diff --git a/src/rewrite_options.rs b/src/rewrite_options.rs index 50950eb5..5c55c2db 100644 --- a/src/rewrite_options.rs +++ b/src/rewrite_options.rs @@ -35,7 +35,7 @@ fn rewrite_options_to_implement_color_only(opt: &mut cli::Opt) { /// Implement --navigate fn rewrite_options_to_implement_navigate(opt: &mut cli::Opt, arg_matches: &clap::ArgMatches) { if opt.navigate { - // Hack: perhaps navigate should be a built-in preset + // Hack: perhaps navigate should be a built-in feature let default_value = ""; if !user_supplied_option("file-modified-label", arg_matches) && opt.file_modified_label == default_value diff --git a/src/set_options.rs b/src/set_options.rs index f1eb9833..6fdbedae 100644 --- a/src/set_options.rs +++ b/src/set_options.rs @@ -3,8 +3,8 @@ use structopt::clap; use crate::cli; use crate::config; +use crate::features; use crate::git_config::{self, GitConfigGet}; -use crate::presets; // A type T implementing this trait gains a static method allowing an option value of type T to be // looked up, implementing delta's rules for looking up option values. @@ -12,28 +12,28 @@ trait GetOptionValue { // If the value for option name n was not supplied on the command line, then a search is performed // as follows. The first value encountered is used: // - // 1. For each preset p (moving right to left through the listed presets): - // 1.1 The value of n under p interpreted as a user-supplied preset (i.e. git config value + // 1. For each feature p (moving right to left through the listed features): + // 1.1 The value of n under p interpreted as a user-supplied feature (i.e. git config value // delta.$p.$n) - // 1.2 The value for n under p interpreted as a builtin preset + // 1.2 The value for n under p interpreted as a builtin feature // 3. The value for n in the main git config section for delta (i.e. git config value delta.$n) fn get_option_value( option_name: &str, - builtin_presets: &HashMap<String, presets::BuiltinPreset>, + builtin_features: &HashMap<String, features::BuiltinFeature>, opt: &cli::Opt, git_config: &mut Option<git_config::GitConfig>, ) -> Option<Self> where Self: Sized, Self: GitConfigGet, - Self: From<presets::OptionValue>, + Self: From<features::OptionValue>, { - if let Some(presets) = &opt.presets { - for preset in presets.to_lowercase().split_whitespace().rev() { - if let Some(value) = Self::get_option_value_for_preset( + if let Some(features) = &opt.features { + for feature in features.to_lowercase().split_whitespace().rev() { + if let Some(value) = Self::get_option_value_for_feature( option_name, - &preset, - &builtin_presets, + &feature, + &builtin_features, opt, git_config, ) { @@ -49,27 +49,27 @@ trait GetOptionValue { None } - fn get_option_value_for_preset( + fn get_option_value_for_feature( option_name: &str, - preset: &str, - builtin_presets: &HashMap<String, presets::BuiltinPreset>, + feature: &str, + builtin_features: &HashMap<String, features::BuiltinFeature>, opt: &cli::Opt, git_config: &mut Option<git_config::GitConfig>, ) -> Option<Self> where Self: Sized, Self: GitConfigGet, - Self: From<presets::OptionValue>, + Self: From<features::OptionValue>, { if let Some(git_config) = git_config { if let Some(value) = - git_config.get::<Self>(&format!("delta.{}.{}", preset, option_name)) + git_config.get::<Self>(&format!("delta.{}.{}", feature, option_name)) { return Some(value); } } - if let Some(builtin_preset) = builtin_presets.get(preset) { - if let Some(value_function) = builtin_preset.get(option_name) { + if let Some(builtin_feature) = builtin_features.get(feature) { + if let Some(value_function) = builtin_feature.get(option_name) { return Some(value_function(opt, &git_config).into()); } } @@ -85,24 +85,24 @@ impl GetOptionValue for usize {} fn get_option_value<T>( option_name: &str, - builtin_presets: &HashMap<String, presets::BuiltinPreset>, + builtin_features: &HashMap<String, features::BuiltinFeature>, opt: &cli::Opt, git_config: &mut Option<git_config::GitConfig>, ) -> Option<T> where T: GitConfigGet, T: GetOptionValue, - T: From<presets::OptionValue>, + T: From<features::OptionValue>, { - T::get_option_value(option_name, builtin_presets, opt, git_config) + T::get_option_value(option_name, builtin_features, opt, git_config) } macro_rules! set_options { ([$( ($option_name:expr, $field_ident:ident) ),* ], - $opt:expr, $builtin_presets:expr, $git_config:expr, $arg_matches:expr) => { + $opt:expr, $builtin_features:expr, $git_config:expr, $arg_matches:expr) => { $( if !$crate::config::user_supplied_option($option_name, $arg_matches) { - if let Some(value) = get_option_value($option_name, &$builtin_presets, $opt, $git_config) { + if let Some(value) = get_option_value($option_name, &$builtin_features, $opt, $git_config) { $opt.$field_ident = value; } }; @@ -131,8 +131,8 @@ pub fn set_options( set_options!( [ - // --presets must be set first - ("presets", presets), + // --features must be set first + ("features", features), ("color-only", color_only), ("commit-decoration-style", commit_decoration_style), ("commit-style", commit_style), @@ -181,7 +181,7 @@ pub fn set_options( ("zero-style", zero_style) ], opt, - presets::make_builtin_presets(), + features::make_builtin_features(), git_config, arg_matches ); |