summaryrefslogtreecommitdiffstats
path: root/src/options/set.rs
diff options
context:
space:
mode:
authorryuta69 <eyma22s.yu@gmail.com>2020-07-31 07:11:09 +0900
committerGitHub <noreply@github.com>2020-07-30 18:11:09 -0400
commit1249df9d438c98d8da5bab273e180d88d4d50b38 (patch)
tree38f9c79f6291f1f63dab3eb14d7a2c2b7053d1df /src/options/set.rs
parentc5733826b988fe54fbc0298512e222ba057df3bc (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/options/set.rs')
-rw-r--r--src/options/set.rs46
1 files changed, 44 insertions, 2 deletions
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();
+ }
}