From 7ed3c2c3ee494dab25fd76b220da7c716a9b731f Mon Sep 17 00:00:00 2001 From: ulwlu Date: Sun, 15 Aug 2021 21:54:02 +0900 Subject: [PATCH 1/5] Make truecolor option honorable from gitconfig --- src/options/set.rs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/options/set.rs b/src/options/set.rs index 063c999c4..476a0f8e1 100644 --- a/src/options/set.rs +++ b/src/options/set.rs @@ -93,7 +93,7 @@ pub fn set_options( set_widths(opt, git_config, arg_matches, &option_names); // Set light, dark, and syntax-theme. - set_true_color(opt); + set_true_color(opt, git_config, arg_matches, &option_names); set__light__dark__syntax_theme__options(opt, git_config, arg_matches, &option_names); theme::set__is_light_mode__syntax_theme__syntax_set(opt, assets); @@ -556,14 +556,31 @@ fn set_widths( background_color_extends_to_terminal_width; } -fn set_true_color(opt: &mut cli::Opt) { +fn set_true_color( + opt: &mut cli::Opt, + git_config: &mut Option, + arg_matches: &clap::ArgMatches, + option_names: &HashMap<&str, &str>, +) { if opt.true_color == "auto" { // It's equal to its default, so the user might be using the deprecated // --24-bit-color option. if let Some(_24_bit_color) = opt._24_bit_color.as_ref() { opt.true_color = _24_bit_color.clone(); + } else { + let empty_builtin_features = HashMap::new(); + set_options!( + [true_color], + opt, + &empty_builtin_features, + git_config, + arg_matches, + option_names, + false + ); } } + opt.computed.true_color = match opt.true_color.as_ref() { "always" => true, "never" => false, From 93e081985fe7192f7cb6f472ae8d6fb835cdc0e4 Mon Sep 17 00:00:00 2001 From: Dan Davison Date: Sun, 15 Aug 2021 17:13:23 -0700 Subject: [PATCH 2/5] Add test that true-color can be read from git config The new test fails before 7ed3c2c3ee494dab25fd76b220da7c716a9b731f --- src/config.rs | 22 ++++++++++++++++++++++ src/options/set.rs | 1 + 2 files changed, 23 insertions(+) diff --git a/src/config.rs b/src/config.rs index 573a08ed5..c99f7ba41 100644 --- a/src/config.rs +++ b/src/config.rs @@ -496,3 +496,25 @@ pub fn delta_unreachable(message: &str) -> ! { ); process::exit(error_exit_code); } + +#[cfg(test)] +pub mod tests { + use crate::tests::integration_test_utils; + use std::fs::remove_file; + + #[test] + fn test_get_true_color_from_config() { + let git_config_contents = r#" +[delta] + true-color = never +"#; + let git_config_path = "delta__test_get_true_color_from_config.gitconfig"; + let config = integration_test_utils::make_config_from_args_and_git_config( + &[], + Some(git_config_contents.as_bytes()), + Some(git_config_path), + ); + assert!(!config.true_color); + remove_file(git_config_path).unwrap(); + } +} diff --git a/src/options/set.rs b/src/options/set.rs index 476a0f8e1..5d952aa62 100644 --- a/src/options/set.rs +++ b/src/options/set.rs @@ -743,6 +743,7 @@ pub mod tests { assert_eq!(opt.side_by_side, true); assert_eq!(opt.syntax_theme, Some("xxxyyyzzz".to_string())); assert_eq!(opt.tab_width, 77); + assert_eq!(opt.true_color, "never"); assert_eq!(opt.whitespace_error_style, "black black"); assert_eq!(opt.width, Some("77".to_string())); assert_eq!(opt.tokenization_regex, "xxxyyyzzz"); From 62495a2cdc504540c4a4ce278770ec68c44b7c8e Mon Sep 17 00:00:00 2001 From: ulwlu Date: Tue, 17 Aug 2021 18:10:04 +0900 Subject: [PATCH 3/5] Place computing process after set_options --- src/options/set.rs | 46 ++++++---------------------------------------- 1 file changed, 6 insertions(+), 40 deletions(-) diff --git a/src/options/set.rs b/src/options/set.rs index 5d952aa62..1a1f9119e 100644 --- a/src/options/set.rs +++ b/src/options/set.rs @@ -90,12 +90,8 @@ pub fn set_options( 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, git_config, arg_matches, &option_names); 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()) { @@ -192,6 +188,10 @@ pub fn set_options( true ); + // Setting ComputedValues + set_widths(opt); + set_true_color(opt); + theme::set__is_light_mode__syntax_theme__syntax_set(opt, assets); opt.computed.inspect_raw_lines = cli::InspectRawLines::from_str(&opt.inspect_raw_lines).unwrap(); opt.computed.paging_mode = parse_paging_mode(&opt.paging_mode); @@ -514,28 +514,10 @@ fn parse_paging_mode(paging_mode_string: &str) -> PagingMode { } } -fn set_widths( - opt: &mut cli::Opt, - git_config: &mut Option, - arg_matches: &clap::ArgMatches, - option_names: &HashMap<&str, &str>, -) { +fn set_widths(opt: &mut cli::Opt) { // 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), @@ -556,28 +538,12 @@ fn set_widths( background_color_extends_to_terminal_width; } -fn set_true_color( - opt: &mut cli::Opt, - git_config: &mut Option, - arg_matches: &clap::ArgMatches, - option_names: &HashMap<&str, &str>, -) { +fn set_true_color(opt: &mut cli::Opt) { if opt.true_color == "auto" { // It's equal to its default, so the user might be using the deprecated // --24-bit-color option. if let Some(_24_bit_color) = opt._24_bit_color.as_ref() { opt.true_color = _24_bit_color.clone(); - } else { - let empty_builtin_features = HashMap::new(); - set_options!( - [true_color], - opt, - &empty_builtin_features, - git_config, - arg_matches, - option_names, - false - ); } } From 1ee71c721fcf974a50d7f1a60773d2e561d141da Mon Sep 17 00:00:00 2001 From: ulwlu Date: Tue, 17 Aug 2021 18:10:36 +0900 Subject: [PATCH 4/5] Add test for checking if values requre computing set correctly --- src/config.rs | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/config.rs b/src/config.rs index c99f7ba41..9dfea5d4f 100644 --- a/src/config.rs +++ b/src/config.rs @@ -499,22 +499,34 @@ pub fn delta_unreachable(message: &str) -> ! { #[cfg(test)] pub mod tests { + use crate::bat_utils::output::PagingMode; + use crate::cli; use crate::tests::integration_test_utils; use std::fs::remove_file; #[test] - fn test_get_true_color_from_config() { - let git_config_contents = r#" + fn test_get_computed_values_from_config() { + let git_config_contents = b" [delta] true-color = never -"#; + width = 100 + inspect-raw-lines = true + paging = never + syntax-theme = None +"; let git_config_path = "delta__test_get_true_color_from_config.gitconfig"; let config = integration_test_utils::make_config_from_args_and_git_config( &[], - Some(git_config_contents.as_bytes()), + Some(git_config_contents), Some(git_config_path), ); - assert!(!config.true_color); + assert_eq!(config.true_color, false); + assert_eq!(config.decorations_width, cli::Width::Fixed(100)); + assert_eq!(config.background_color_extends_to_terminal_width, true); + assert_eq!(config.inspect_raw_lines, cli::InspectRawLines::True); + assert_eq!(config.paging_mode, PagingMode::Never); + assert!(config.syntax_theme.is_none()); + // syntax_set doesn't depend on gitconfig. remove_file(git_config_path).unwrap(); } } From d7ac0ceacf8b371cb0d3412ccc442b66d5b36657 Mon Sep 17 00:00:00 2001 From: ulwlu Date: Tue, 17 Aug 2021 18:10:57 +0900 Subject: [PATCH 5/5] Remove unnecessary computed values candidate --- src/cli.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/cli.rs b/src/cli.rs index 72e91b5ae..70ecd0936 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -637,7 +637,6 @@ pub struct ComputedValues { pub inspect_raw_lines: InspectRawLines, pub is_light_mode: bool, pub paging_mode: PagingMode, - pub syntax_dummy_theme: SyntaxTheme, pub syntax_set: SyntaxSet, pub syntax_theme: Option, pub true_color: bool,