diff options
author | ryuta69 <eyma22s.yu@gmail.com> | 2020-07-31 07:11:09 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-30 18:11:09 -0400 |
commit | 1249df9d438c98d8da5bab273e180d88d4d50b38 (patch) | |
tree | 38f9c79f6291f1f63dab3eb14d7a2c2b7053d1df /src | |
parent | c5733826b988fe54fbc0298512e222ba057df3bc (diff) |
Honor width option in git_config
* Update width to accept gitconfig value
* Feature set width from gitconfig only when cli option is not supplied
* Add unittest of width in gitconfig
* Delete duplicate field of width
It's already roled by decorations_width.
* Fix show_config of width with decorations_width
* Fix test not with static number but dynamic variable
* Fix the way of getting value of user configured width
use gather_builtin_features_recursively in set_options is the ideal way,
it can get inside custom_features and set as option.
* Refactor checking if none
* Fix if width is assigned variable then output variable
Diffstat (limited to 'src')
-rw-r--r-- | src/cli.rs | 2 | ||||
-rw-r--r-- | src/main.rs | 5 | ||||
-rw-r--r-- | src/options/set.rs | 46 |
3 files changed, 50 insertions, 3 deletions
@@ -560,7 +560,7 @@ pub struct ComputedValues { pub paging_mode: PagingMode, } -#[derive(Clone, Debug)] +#[derive(Clone, Debug, PartialEq)] pub enum Width { Fixed(usize), Variable, diff --git a/src/main.rs b/src/main.rs index f66bf489..68954326 100644 --- a/src/main.rs +++ b/src/main.rs @@ -185,6 +185,7 @@ fn show_config(config: &config::Config) { navigate = {navigate} paging = {paging_mode} syntax-theme = {syntax_theme} + width = {width} tabs = {tab_width} word-diff-regex = {tokenization_regex}", true_color = config.true_color, @@ -205,6 +206,10 @@ fn show_config(config: &config::Config) { .clone() .map(|t| t.name.unwrap_or("none".to_string())) .unwrap_or("none".to_string()), + width = match config.decorations_width { + cli::Width::Fixed(width) => width.to_string(), + cli::Width::Variable => "variable".to_string() + }, tab_width = config.tab_width, tokenization_regex = format_option_value(&config.tokenization_regex.to_string()), ); diff --git a/src/options/set.rs b/src/options/set.rs index 6be35bf6..40582f60 100644 --- a/src/options/set.rs +++ b/src/options/set.rs @@ -81,7 +81,7 @@ pub fn set_options( let features = gather_features(opt, &builtin_features, git_config); opt.features = features.join(" "); - set_widths(opt); + set_widths(opt, git_config, arg_matches, &option_names); // Set light, dark, and syntax-theme. set_true_color(opt); @@ -479,9 +479,28 @@ fn parse_paging_mode(paging_mode_string: &str) -> PagingMode { } } -fn set_widths(opt: &mut cli::Opt) { +fn set_widths( + opt: &mut cli::Opt, + git_config: &mut Option<git_config::GitConfig>, + arg_matches: &clap::ArgMatches, + option_names: &HashMap<&str, &str>, +) { // Allow one character in case e.g. `less --status-column` is in effect. See #41 and #10. opt.computed.available_terminal_width = (Term::stdout().size().1 - 1) as usize; + + let empty_builtin_features = HashMap::new(); + if opt.width.is_none() { + set_options!( + [width], + opt, + &empty_builtin_features, + git_config, + arg_matches, + option_names, + false + ); + } + let (decorations_width, background_color_extends_to_terminal_width) = match opt.width.as_deref() { Some("variable") => (cli::Width::Variable, false), @@ -545,6 +564,7 @@ pub mod tests { use crate::bat::output::PagingMode; use crate::tests::integration_test_utils::integration_test_utils; + use crate::cli; #[test] fn test_options_can_be_set_in_git_config() { @@ -656,4 +676,26 @@ pub mod tests { remove_file(git_config_path).unwrap(); } + + #[test] + fn test_width_in_git_config_is_honored() { + let git_config_contents = b" +[delta] + features = my-width-feature + +[delta \"my-width-feature\"] + width = variable +"; + let git_config_path = "delta__test_width_in_git_config_is_honored.gitconfig"; + + let opt = integration_test_utils::make_options_from_args_and_git_config( + &[], + Some(git_config_contents), + Some(git_config_path), + ); + + assert_eq!(opt.computed.decorations_width, cli::Width::Variable); + + remove_file(git_config_path).unwrap(); + } } |