From 587a01ea976dcebadfc5a15b32344fb20b2c96e6 Mon Sep 17 00:00:00 2001 From: Catherine Noll Date: Sat, 20 Mar 2021 18:46:30 -0500 Subject: Skeleton for show-themes command line option --- src/cli.rs | 6 ++++++ src/main.rs | 7 +++++++ src/options/set.rs | 1 + 3 files changed, 14 insertions(+) diff --git a/src/cli.rs b/src/cli.rs index 41f6eb89..78c3e179 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -270,6 +270,12 @@ pub struct Opt { #[structopt(long = "show-syntax-themes")] pub show_syntax_themes: bool, + /// Show all available delta themes, each with an example of highlighted diff output. + /// If diff output is supplied on standard input then this will be used for the demo. For + /// example: `git show --color=always | delta --show-themes`. + #[structopt(long = "show-themes")] + pub show_themes: bool, + #[structopt(long = "no-gitconfig")] /// Do not take any settings from git config. See GIT CONFIG section. pub no_gitconfig: bool, diff --git a/src/main.rs b/src/main.rs index 5757fbab..35662b45 100644 --- a/src/main.rs +++ b/src/main.rs @@ -65,6 +65,9 @@ fn run_app() -> std::io::Result { } else if opt.show_syntax_themes { show_syntax_themes()?; return Ok(0); + } else if opt.show_themes { + show_themes()?; + return Ok(0); } let _show_config = opt.show_config; @@ -302,6 +305,10 @@ where } } +fn show_themes() -> std::io::Result<()> { + Ok(()) +} + #[cfg(not(tarpaulin_include))] fn show_syntax_themes() -> std::io::Result<()> { let mut opt = cli::Opt::from_args(); diff --git a/src/options/set.rs b/src/options/set.rs index 354eeea6..e5c1edf0 100644 --- a/src/options/set.rs +++ b/src/options/set.rs @@ -169,6 +169,7 @@ pub fn set_options( plus_empty_line_marker_style, plus_non_emph_style, raw, + show_themes, side_by_side, tab_width, tokenization_regex, -- cgit v1.2.3 From 0c1b7b89b025aacfe12a418e067f449a9a0946fa Mon Sep 17 00:00:00 2001 From: Catherine Noll Date: Sat, 20 Mar 2021 19:26:50 -0500 Subject: Cycle through a constant list of themes --- src/main.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/main.rs b/src/main.rs index 35662b45..8fd8dd10 100644 --- a/src/main.rs +++ b/src/main.rs @@ -305,7 +305,27 @@ where } } +const THEMES: [&'static str; 4] = [ + "collared-trogon", + "tangara-chilensis", + "villsau", + "woolly-mammoth", +]; + fn show_themes() -> std::io::Result<()> { + let mut output_type = OutputType::from_mode( + PagingMode::QuitIfOneScreen, + None, + &config::Config::from(cli::Opt::default()), + ) + .unwrap(); + let title_style = ansi_term::Style::new().bold(); + let writer = output_type.handle().unwrap(); + + for theme in &THEMES { + writeln!(writer, "\n\nTheme: {}\n", title_style.paint(*theme))?; + } + Ok(()) } -- cgit v1.2.3 From e561a51371365da845e13b91617cc0aaa2d92ef1 Mon Sep 17 00:00:00 2001 From: Catherine Noll Date: Sat, 20 Mar 2021 20:39:01 -0500 Subject: Apply themes to a hardcoded diff --- src/cli.rs | 2 -- src/main.rs | 30 ++++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/cli.rs b/src/cli.rs index 78c3e179..781fd644 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -1,5 +1,4 @@ use std::collections::{HashMap, HashSet}; -#[cfg(test)] use std::ffi::OsString; use std::path::PathBuf; @@ -641,7 +640,6 @@ impl Opt { Self::from_clap_and_git_config(Self::clap().get_matches(), git_config, assets) } - #[cfg(test)] pub fn from_iter_and_git_config(iter: I, git_config: &mut Option) -> Self where I: IntoIterator, diff --git a/src/main.rs b/src/main.rs index 8fd8dd10..82e41536 100644 --- a/src/main.rs +++ b/src/main.rs @@ -313,6 +313,25 @@ const THEMES: [&'static str; 4] = [ ]; fn show_themes() -> std::io::Result<()> { + use bytelines::ByteLines; + use std::io::BufReader; + let input = b"\ +diff --git a/example.rs b/example.rs +index f38589a..0f1bb83 100644 +--- a/example.rs ++++ b/example.rs +@@ -1,5 +1,5 @@ +-// Output the square of a number. +-fn print_square(num: f64) { +- let result = f64::powf(num, 2.0); +- println!(\"The square of {:.2} is {:.2}.\", num, result); ++// Output the cube of a number. ++fn print_cube(num: f64) { ++ let result = f64::powf(num, 3.0); ++ println!(\"The cube of {:.2} is {:.2}.\", num, result); +" + .to_vec(); + let mut output_type = OutputType::from_mode( PagingMode::QuitIfOneScreen, None, @@ -324,6 +343,17 @@ fn show_themes() -> std::io::Result<()> { for theme in &THEMES { writeln!(writer, "\n\nTheme: {}\n", title_style.paint(*theme))?; + let opt = cli::Opt::from_iter_and_git_config( + &["", "", "--features", theme], + &mut git_config::GitConfig::try_create(), + ); + let config = config::Config::from(opt); + if let Err(error) = delta(ByteLines::new(BufReader::new(&input[0..])), writer, &config) { + match error.kind() { + ErrorKind::BrokenPipe => process::exit(0), + _ => eprintln!("{}", error), + } + }; } Ok(()) -- cgit v1.2.3 From cc1bf64939f3ae6af21dc258e4a5aeb78d202ecb Mon Sep 17 00:00:00 2001 From: Catherine Noll Date: Sat, 20 Mar 2021 22:54:53 -0500 Subject: Use a sample diff for displaying themes --- src/main.rs | 31 +++----- src/sample_diff.rs | 224 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 236 insertions(+), 19 deletions(-) create mode 100644 src/sample_diff.rs diff --git a/src/main.rs b/src/main.rs index 82e41536..b03b95a3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -22,6 +22,7 @@ mod options; mod paint; mod parse; mod parse_style; +mod sample_diff; mod style; mod syntect_color; mod tests; @@ -315,27 +316,19 @@ const THEMES: [&'static str; 4] = [ fn show_themes() -> std::io::Result<()> { use bytelines::ByteLines; use std::io::BufReader; - let input = b"\ -diff --git a/example.rs b/example.rs -index f38589a..0f1bb83 100644 ---- a/example.rs -+++ b/example.rs -@@ -1,5 +1,5 @@ --// Output the square of a number. --fn print_square(num: f64) { -- let result = f64::powf(num, 2.0); -- println!(\"The square of {:.2} is {:.2}.\", num, result); -+// Output the cube of a number. -+fn print_cube(num: f64) { -+ let result = f64::powf(num, 3.0); -+ println!(\"The cube of {:.2} is {:.2}.\", num, result); -" - .to_vec(); + use sample_diff::DIFF; + let input = &DIFF.to_vec(); + + let mut git_config = git_config::GitConfig::try_create(); + let opt = cli::Opt::from_iter_and_git_config( + &["", "", "--navigate"], + &mut git_config, + ); let mut output_type = OutputType::from_mode( - PagingMode::QuitIfOneScreen, + PagingMode::Always, None, - &config::Config::from(cli::Opt::default()), + &config::Config::from(opt), ) .unwrap(); let title_style = ansi_term::Style::new().bold(); @@ -345,7 +338,7 @@ index f38589a..0f1bb83 100644 writeln!(writer, "\n\nTheme: {}\n", title_style.paint(*theme))?; let opt = cli::Opt::from_iter_and_git_config( &["", "", "--features", theme], - &mut git_config::GitConfig::try_create(), + &mut git_config, ); let config = config::Config::from(opt); if let Err(error) = delta(ByteLines::new(BufReader::new(&input[0..])), writer, &config) { diff --git a/src/sample_diff.rs b/src/sample_diff.rs new file mode 100644 index 00000000..2481f8d3 --- /dev/null +++ b/src/sample_diff.rs @@ -0,0 +1,224 @@ +pub const DIFF: &[u8; 8715] = b"\ +commit dc267979a46caee4d79ed2e3d17af9bd513c4e39 +Author: Dan Davison +Date: Fri Jan 8 10:33:55 2021 -0500 + + Prevent tests setting env vars from affecting other tests + +diff --git a/src/git_config/git_config.rs b/src/git_config/git_config.rs +index 9620960..d95a6b1 100644 +--- a/src/git_config/git_config.rs ++++ b/src/git_config/git_config.rs +@@ -42,10 +42,14 @@ impl GitConfig { + } + + #[cfg(test)] +- pub fn from_path(path: &Path) -> Self { ++ pub fn from_path(path: &Path, honor_env_var: bool) -> Self { + Self { + config: git2::Config::open(path).unwrap(), +- config_from_env_var: parse_config_from_env_var(), ++ config_from_env_var: if honor_env_var { ++ parse_config_from_env_var() ++ } else { ++ HashMap::new() ++ }, + repo: None, + enabled: true, + } +diff --git a/src/options/get.rs b/src/options/get.rs +index f19c329..a36987c 100644 +--- a/src/options/get.rs ++++ b/src/options/get.rs +@@ -117,8 +117,13 @@ pub mod tests { + + use crate::tests::integration_test_utils::integration_test_utils; + ++ // TODO: the followig tests are collapsed into one since they all set the same env var and thus ++ // could affect each other if allowed to run concurrently. ++ + #[test] +- fn test_simple_string_env_var_overrides_git_config() { ++ fn test_env_var_overrides_git_config() { ++ // ---------------------------------------------------------------------------------------- ++ // simple string + let git_config_contents = b\" + [delta] + plus-style = blue +@@ -133,7 +138,7 @@ pub mod tests { + assert_eq!(opt.plus_style, \"blue\"); + + env::set_var(\"GIT_CONFIG_PARAMETERS\", \"'delta.plus-style=green'\"); +- let opt = integration_test_utils::make_options_from_args_and_git_config( ++ let opt = integration_test_utils::make_options_from_args_and_git_config_honoring_env_var( + &[], + Some(git_config_contents), + Some(git_config_path), +@@ -141,10 +146,9 @@ pub mod tests { + assert_eq!(opt.plus_style, \"green\"); + + remove_file(git_config_path).unwrap(); +- } + +- #[test] +- fn test_complex_string_env_var_overrides_git_config() { ++ // ---------------------------------------------------------------------------------------- ++ // complex string + let git_config_contents = br##\" + [delta] + minus-style = red bold ul \"#ffeeee\" +@@ -162,7 +166,7 @@ pub mod tests { + \"GIT_CONFIG_PARAMETERS\", + r##\"'delta.minus-style=magenta italic ol \"#aabbcc\"'\"##, + ); +- let opt = integration_test_utils::make_options_from_args_and_git_config( ++ let opt = integration_test_utils::make_options_from_args_and_git_config_honoring_env_var( + &[], + Some(git_config_contents), + Some(git_config_path), +@@ -170,10 +174,9 @@ pub mod tests { + assert_eq!(opt.minus_style, r##\"magenta italic ol \"#aabbcc\"\"##,); + + remove_file(git_config_path).unwrap(); +- } + +- #[test] +- fn test_option_string_env_var_overrides_git_config() { ++ // ---------------------------------------------------------------------------------------- ++ // option string + let git_config_contents = b\" + [delta] + plus-style = blue +@@ -188,7 +191,7 @@ pub mod tests { + assert_eq!(opt.plus_style, \"blue\"); + + env::set_var(\"GIT_CONFIG_PARAMETERS\", \"'delta.plus-style=green'\"); +- let opt = integration_test_utils::make_options_from_args_and_git_config( ++ let opt = integration_test_utils::make_options_from_args_and_git_config_honoring_env_var( + &[], + Some(git_config_contents), + Some(git_config_path), +@@ -196,10 +199,9 @@ pub mod tests { + assert_eq!(opt.plus_style, \"green\"); + + remove_file(git_config_path).unwrap(); +- } + +- #[test] +- fn test_bool_env_var_overrides_git_config() { ++ // ---------------------------------------------------------------------------------------- ++ // bool + let git_config_contents = b\" + [delta] + side-by-side = true +@@ -214,7 +216,7 @@ pub mod tests { + assert_eq!(opt.side_by_side, true); + + env::set_var(\"GIT_CONFIG_PARAMETERS\", \"'delta.side-by-side=false'\"); +- let opt = integration_test_utils::make_options_from_args_and_git_config( ++ let opt = integration_test_utils::make_options_from_args_and_git_config_honoring_env_var( + &[], + Some(git_config_contents), + Some(git_config_path), +@@ -222,10 +224,9 @@ pub mod tests { + assert_eq!(opt.side_by_side, false); + + remove_file(git_config_path).unwrap(); +- } + +- #[test] +- fn test_int_env_var_overrides_git_config() { ++ // ---------------------------------------------------------------------------------------- ++ // int + let git_config_contents = b\" + [delta] + max-line-length = 1 +@@ -240,7 +241,7 @@ pub mod tests { + assert_eq!(opt.max_line_length, 1); + + env::set_var(\"GIT_CONFIG_PARAMETERS\", \"'delta.max-line-length=2'\"); +- let opt = integration_test_utils::make_options_from_args_and_git_config( ++ let opt = integration_test_utils::make_options_from_args_and_git_config_honoring_env_var( + &[], + Some(git_config_contents), + Some(git_config_path), +@@ -248,17 +249,16 @@ pub mod tests { + assert_eq!(opt.max_line_length, 2); + + remove_file(git_config_path).unwrap(); +- } + +- #[test] +- fn test_float_env_var_overrides_git_config() { ++ // ---------------------------------------------------------------------------------------- ++ // float + let git_config_contents = b\" + [delta] + max-line-distance = 0.6 + \"; + let git_config_path = \"delta__test_float_env_var_overrides_git_config.gitconfig\"; + +- let opt = integration_test_utils::make_options_from_args_and_git_config( ++ let opt = integration_test_utils::make_options_from_args_and_git_config_honoring_env_var( + &[], + Some(git_config_contents), + Some(git_config_path), +@@ -266,7 +266,7 @@ pub mod tests { + assert_eq!(opt.max_line_distance, 0.6); + + env::set_var(\"GIT_CONFIG_PARAMETERS\", \"'delta.max-line-distance=0.7'\"); +- let opt = integration_test_utils::make_options_from_args_and_git_config( ++ let opt = integration_test_utils::make_options_from_args_and_git_config_honoring_env_var( + &[], + Some(git_config_contents), + Some(git_config_path), +diff --git a/src/tests/integration_test_utils.rs b/src/tests/integration_test_utils.rs +index 37ae057..8eb3674 100644 +--- a/src/tests/integration_test_utils.rs ++++ b/src/tests/integration_test_utils.rs +@@ -17,12 +17,29 @@ pub mod integration_test_utils { + args: &[&str], + git_config_contents: Option<&[u8]>, + git_config_path: Option<&str>, ++ ) -> cli::Opt { ++ _make_options_from_args_and_git_config(args, git_config_contents, git_config_path, false) ++ } ++ ++ pub fn make_options_from_args_and_git_config_honoring_env_var( ++ args: &[&str], ++ git_config_contents: Option<&[u8]>, ++ git_config_path: Option<&str>, ++ ) -> cli::Opt { ++ _make_options_from_args_and_git_config(args, git_config_contents, git_config_path, true) ++ } ++ ++ fn _make_options_from_args_and_git_config( ++ args: &[&str], ++ git_config_contents: Option<&[u8]>, ++ git_config_path: Option<&str>, ++ honor_env_var: bool, + ) -> cli::Opt { + let mut args: Vec<&str> = itertools::chain(&[\"/dev/null\", \"/dev/null\"], args) + .map(|s| *s) + .collect(); + let mut git_config = match (git_config_contents, git_config_path) { +- (Some(contents), Some(path)) => Some(make_git_config(contents, path)), ++ (Some(contents), Some(path)) => Some(make_git_config(contents, path, honor_env_var)), + _ => { + args.push(\"--no-gitconfig\"); + None +@@ -52,11 +69,11 @@ pub mod integration_test_utils { + config::Config::from(make_options_from_args(args)) + } + +- fn make_git_config(contents: &[u8], path: &str) -> GitConfig { ++ fn make_git_config(contents: &[u8], path: &str, honor_env_var: bool) -> GitConfig { + let path = Path::new(path); + let mut file = File::create(path).unwrap(); + file.write_all(contents).unwrap(); +- GitConfig::from_path(&path) ++ GitConfig::from_path(&path, honor_env_var) + } + + pub fn get_line_of_code_from_delta( +"; -- cgit v1.2.3 From 43f971512594d931b97a61313612601ea5af6d0c Mon Sep 17 00:00:00 2001 From: Catherine Noll Date: Sat, 20 Mar 2021 23:08:27 -0500 Subject: Add functionality to cycle through themes using a diff from stdin --- src/main.rs | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/src/main.rs b/src/main.rs index b03b95a3..d48a2961 100644 --- a/src/main.rs +++ b/src/main.rs @@ -315,31 +315,30 @@ const THEMES: [&'static str; 4] = [ fn show_themes() -> std::io::Result<()> { use bytelines::ByteLines; - use std::io::BufReader; use sample_diff::DIFF; - let input = &DIFF.to_vec(); + use std::io::BufReader; + let mut input = DIFF.to_vec(); + + if !atty::is(atty::Stream::Stdin) { + let mut buf = Vec::new(); + io::stdin().lock().read_to_end(&mut buf)?; + if !buf.is_empty() { + input = buf; + } + }; let mut git_config = git_config::GitConfig::try_create(); - let opt = cli::Opt::from_iter_and_git_config( - &["", "", "--navigate"], - &mut git_config, - ); + let opt = cli::Opt::from_iter_and_git_config(&["", "", "--navigate"], &mut git_config); - let mut output_type = OutputType::from_mode( - PagingMode::Always, - None, - &config::Config::from(opt), - ) - .unwrap(); + let mut output_type = + OutputType::from_mode(PagingMode::Always, None, &config::Config::from(opt)).unwrap(); let title_style = ansi_term::Style::new().bold(); let writer = output_type.handle().unwrap(); for theme in &THEMES { writeln!(writer, "\n\nTheme: {}\n", title_style.paint(*theme))?; - let opt = cli::Opt::from_iter_and_git_config( - &["", "", "--features", theme], - &mut git_config, - ); + let opt = + cli::Opt::from_iter_and_git_config(&["", "", "--features", theme], &mut git_config); let config = config::Config::from(opt); if let Err(error) = delta(ByteLines::new(BufReader::new(&input[0..])), writer, &config) { match error.kind() { -- cgit v1.2.3 From 3572ec451f78270fc5aa8348e6ac716a32ab366c Mon Sep 17 00:00:00 2001 From: Catherine Noll Date: Sun, 21 Mar 2021 11:45:54 -0500 Subject: Navigate from theme to theme with n/N when --show-themes --- src/config.rs | 31 ++++++++++++++++++++++++++----- src/features/navigate.rs | 26 +++++++++++++++++--------- src/main.rs | 10 +++++++++- 3 files changed, 52 insertions(+), 15 deletions(-) diff --git a/src/config.rs b/src/config.rs index 23b7b97d..eaa295ea 100644 --- a/src/config.rs +++ b/src/config.rs @@ -13,6 +13,7 @@ use crate::cli; use crate::color; use crate::delta::State; use crate::env; +use crate::features::navigate; use crate::features::side_by_side; use crate::git_config::GitConfigEntry; use crate::style::{self, Style}; @@ -58,6 +59,7 @@ pub struct Config { pub minus_non_emph_style: Style, pub minus_style: Style, pub navigate: bool, + pub navigate_regexp: Option, pub null_style: Style, pub null_syntect_style: SyntectStyle, pub paging_mode: PagingMode, @@ -154,6 +156,24 @@ impl From for Config { _ => *style::GIT_DEFAULT_PLUS_STYLE, }; + let file_added_label = opt.file_added_label; + let file_copied_label = opt.file_copied_label; + let file_modified_label = opt.file_modified_label; + let file_removed_label = opt.file_removed_label; + let file_renamed_label = opt.file_renamed_label; + + let navigate_regexp = if opt.navigate || opt.show_themes { + Some(navigate::make_navigate_regexp( + opt.show_themes, + &file_modified_label, + &file_added_label, + &file_removed_label, + &file_renamed_label, + )) + } else { + None + }; + Self { available_terminal_width: opt.computed.available_terminal_width, background_color_extends_to_terminal_width: opt @@ -163,11 +183,11 @@ impl From for Config { color_only: opt.color_only, decorations_width: opt.computed.decorations_width, error_exit_code: 2, // Use 2 for error because diff uses 0 and 1 for non-error. - file_added_label: opt.file_added_label, - file_copied_label: opt.file_copied_label, - file_modified_label: opt.file_modified_label, - file_removed_label: opt.file_removed_label, - file_renamed_label: opt.file_renamed_label, + file_added_label, + file_copied_label, + file_modified_label, + file_removed_label, + file_renamed_label, file_style, git_config_entries: opt.git_config_entries, hunk_header_file_style, @@ -203,6 +223,7 @@ impl From for Config { minus_non_emph_style, minus_style, navigate: opt.navigate, + navigate_regexp, null_style: Style::new(), null_syntect_style: SyntectStyle::default(), paging_mode: opt.computed.paging_mode, diff --git a/src/features/navigate.rs b/src/features/navigate.rs index a38815a6..0020d54b 100644 --- a/src/features/navigate.rs +++ b/src/features/navigate.rs @@ -23,14 +23,22 @@ pub fn make_feature() -> Vec<(String, OptionValueFunction)> { ]) } -fn make_navigate_regexp(config: &Config) -> String { - format!( - "^(commit|{}|{}|{}|{})", - config.file_modified_label, - config.file_added_label, - config.file_removed_label, - config.file_renamed_label - ) +// Construct the regexp used by less for paging, if --show-themes or --navigate is enabled. +pub fn make_navigate_regexp( + show_themes: bool, + file_modified_label: &str, + file_added_label: &str, + file_removed_label: &str, + file_renamed_label: &str, +) -> String { + if show_themes { + "^Theme:".to_string() + } else { + format!( + "^(commit|{}|{}|{}|{})", + file_modified_label, file_added_label, file_removed_label, file_renamed_label, + ) + } } // Create a less history file to be used by delta's child less process. This file is initialized @@ -57,7 +65,7 @@ pub fn copy_less_hist_file_and_append_navigate_regexp(config: &Config) -> std::i std::fs::File::create(&delta_less_hist_file)?, "{}\"{}", contents, - make_navigate_regexp(config) + config.navigate_regexp.as_ref().unwrap(), )?; Ok(delta_less_hist_file) } diff --git a/src/main.rs b/src/main.rs index d48a2961..35edb03c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -258,6 +258,7 @@ fn show_config(config: &config::Config, writer: &mut dyn Write) -> std::io::Resu " max-line-distance = {max_line_distance} max-line-length = {max_line_length} navigate = {navigate} + navigate-regexp = {navigate_regexp} paging = {paging_mode} side-by-side = {side_by_side} syntax-theme = {syntax_theme} @@ -267,6 +268,10 @@ fn show_config(config: &config::Config, writer: &mut dyn Write) -> std::io::Resu max_line_distance = config.max_line_distance, max_line_length = config.max_line_length, navigate = config.navigate, + navigate_regexp = match &config.navigate_regexp { + None => "".to_string(), + Some(s) => s.to_string(), + }, paging_mode = match config.paging_mode { PagingMode::Always => "always", PagingMode::Never => "never", @@ -328,7 +333,10 @@ fn show_themes() -> std::io::Result<()> { }; let mut git_config = git_config::GitConfig::try_create(); - let opt = cli::Opt::from_iter_and_git_config(&["", "", "--navigate"], &mut git_config); + let opt = cli::Opt::from_iter_and_git_config( + &["", "", "--navigate", "--show-themes"], + &mut git_config, + ); let mut output_type = OutputType::from_mode(PagingMode::Always, None, &config::Config::from(opt)).unwrap(); -- cgit v1.2.3 From 85f591b75297c085ba321e869b1d3a63a0d4837d Mon Sep 17 00:00:00 2001 From: Catherine Noll Date: Sun, 21 Mar 2021 12:50:45 -0500 Subject: Send navigation command to less on --show-themes --- src/bat_utils/output.rs | 3 +++ src/config.rs | 2 ++ 2 files changed, 5 insertions(+) diff --git a/src/bat_utils/output.rs b/src/bat_utils/output.rs index 26cd4e21..388bc0c9 100644 --- a/src/bat_utils/output.rs +++ b/src/bat_utils/output.rs @@ -137,6 +137,9 @@ delta is not an appropriate value for $PAGER \ navigate::copy_less_hist_file_and_append_navigate_regexp(config) { process.env("LESSHISTFILE", hist_file); + if config.show_themes { + process.arg("+n"); + } } } Ok(process diff --git a/src/config.rs b/src/config.rs index eaa295ea..f822efc2 100644 --- a/src/config.rs +++ b/src/config.rs @@ -70,6 +70,7 @@ pub struct Config { pub plus_style: Style, pub git_minus_style: Style, pub git_plus_style: Style, + pub show_themes: bool, pub side_by_side: bool, pub side_by_side_data: side_by_side::SideBySideData, pub syntax_dummy_theme: SyntaxTheme, @@ -234,6 +235,7 @@ impl From for Config { plus_style, git_minus_style, git_plus_style, + show_themes: opt.show_themes, side_by_side: opt.side_by_side, side_by_side_data, syntax_dummy_theme: SyntaxTheme::default(), -- cgit v1.2.3 From cbbc1aab01db4caa24872fd402567d1fc8ee49c3 Mon Sep 17 00:00:00 2001 From: Catherine Noll Date: Sun, 21 Mar 2021 23:03:10 -0400 Subject: Get themes from gitconfig instead of hardcoding --- src/git_config/mod.rs | 2 +- src/main.rs | 39 +++++++++++++++++++++++++++++---------- themes.gitconfig | 4 ++++ 3 files changed, 34 insertions(+), 11 deletions(-) diff --git a/src/git_config/mod.rs b/src/git_config/mod.rs index 827446e1..13b494b9 100644 --- a/src/git_config/mod.rs +++ b/src/git_config/mod.rs @@ -12,7 +12,7 @@ use std::process; use lazy_static::lazy_static; pub struct GitConfig { - config: git2::Config, + pub config: git2::Config, config_from_env_var: HashMap, pub enabled: bool, pub repo: Option, diff --git a/src/main.rs b/src/main.rs index 35edb03c..a90d4871 100644 --- a/src/main.rs +++ b/src/main.rs @@ -27,6 +27,8 @@ mod style; mod syntect_color; mod tests; +use lazy_static::lazy_static; +use regex::Regex; use std::io::{self, ErrorKind, Read, Write}; use std::path::PathBuf; use std::process; @@ -311,12 +313,29 @@ where } } -const THEMES: [&'static str; 4] = [ - "collared-trogon", - "tangara-chilensis", - "villsau", - "woolly-mammoth", -]; +lazy_static! { + static ref GIT_CONFIG_THEME_REGEX: Regex = Regex::new(r"^delta\.(.+)\.is-theme$").unwrap(); +} + +fn get_themes() -> Vec { + let _git_config = git_config::GitConfig::try_create(); + let mut themes: Vec = Vec::new(); + for e in &_git_config.unwrap().config.entries(None).unwrap() { + let entry = e.unwrap(); + let entry_name = entry.name().unwrap(); + let entry_value = entry.value().unwrap(); + dbg!(entry_name, entry_value); + if entry_value == "true" { + let caps = GIT_CONFIG_THEME_REGEX.captures(entry_name); + if let Some(caps) = caps { + // need to check value i.e. whether is_theme = false + let name = caps.get(1).map_or("", |m| m.as_str()).to_string(); + themes.push(name) + } + } + } + themes +} fn show_themes() -> std::io::Result<()> { use bytelines::ByteLines; @@ -337,17 +356,17 @@ fn show_themes() -> std::io::Result<()> { &["", "", "--navigate", "--show-themes"], &mut git_config, ); - let mut output_type = OutputType::from_mode(PagingMode::Always, None, &config::Config::from(opt)).unwrap(); let title_style = ansi_term::Style::new().bold(); let writer = output_type.handle().unwrap(); - for theme in &THEMES { - writeln!(writer, "\n\nTheme: {}\n", title_style.paint(*theme))?; + for theme in &get_themes() { + writeln!(writer, "\n\nTheme: {}\n", title_style.paint(theme))?; let opt = - cli::Opt::from_iter_and_git_config(&["", "", "--features", theme], &mut git_config); + cli::Opt::from_iter_and_git_config(&["", "", "--features", &theme], &mut git_config); let config = config::Config::from(opt); + if let Err(error) = delta(ByteLines::new(BufReader::new(&input[0..])), writer, &config) { match error.kind() { ErrorKind::BrokenPipe => process::exit(0), diff --git a/themes.gitconfig b/themes.gitconfig index 13960e32..3dd4ba1a 100644 --- a/themes.gitconfig +++ b/themes.gitconfig @@ -49,6 +49,7 @@ file-modified-label = [M] file-removed-label = [-] file-renamed-label = [R] + is-theme = true [delta "villsau"] # author: https://github.com/torarnv @@ -69,6 +70,7 @@ plus-emph-style = bold green 22 plus-empty-line-marker-style = normal "#002800" whitespace-error-style = reverse red + is-theme = true [delta "collared-trogon"] # author: https://github.com/clnoll @@ -90,6 +92,7 @@ plus-style = syntax "#001a00" plus-emph-style = syntax "#003300" syntax-theme = Nord + is-theme = true [delta "tangara-chilensis"] # author: https://github.com/clnoll @@ -112,3 +115,4 @@ plus-emph-style = syntax "#03a4ff" side-by-side = true syntax-theme = Vibrant Sunburst + is-theme = true -- cgit v1.2.3 From a1e42432f4413b54249700e59494e261f5718f3a Mon Sep 17 00:00:00 2001 From: Catherine Noll Date: Sat, 27 Mar 2021 19:46:08 -0400 Subject: Reorganize and add test for get_themes --- src/main.rs | 29 ++------------------ src/options/get.rs | 54 +++++++++++++++++++++++++++++++++++++ src/tests/integration_test_utils.rs | 2 +- 3 files changed, 57 insertions(+), 28 deletions(-) diff --git a/src/main.rs b/src/main.rs index a90d4871..fb4628ed 100644 --- a/src/main.rs +++ b/src/main.rs @@ -27,8 +27,6 @@ mod style; mod syntect_color; mod tests; -use lazy_static::lazy_static; -use regex::Regex; use std::io::{self, ErrorKind, Read, Write}; use std::path::PathBuf; use std::process; @@ -41,6 +39,7 @@ use crate::bat_utils::assets::{list_languages, HighlightingAssets}; use crate::bat_utils::output::{OutputType, PagingMode}; use crate::config::delta_unreachable; use crate::delta::delta; +use crate::options::get::get_themes; use crate::options::theme::is_light_syntax_theme; pub mod errors { @@ -313,30 +312,6 @@ where } } -lazy_static! { - static ref GIT_CONFIG_THEME_REGEX: Regex = Regex::new(r"^delta\.(.+)\.is-theme$").unwrap(); -} - -fn get_themes() -> Vec { - let _git_config = git_config::GitConfig::try_create(); - let mut themes: Vec = Vec::new(); - for e in &_git_config.unwrap().config.entries(None).unwrap() { - let entry = e.unwrap(); - let entry_name = entry.name().unwrap(); - let entry_value = entry.value().unwrap(); - dbg!(entry_name, entry_value); - if entry_value == "true" { - let caps = GIT_CONFIG_THEME_REGEX.captures(entry_name); - if let Some(caps) = caps { - // need to check value i.e. whether is_theme = false - let name = caps.get(1).map_or("", |m| m.as_str()).to_string(); - themes.push(name) - } - } - } - themes -} - fn show_themes() -> std::io::Result<()> { use bytelines::ByteLines; use sample_diff::DIFF; @@ -361,7 +336,7 @@ fn show_themes() -> std::io::Result<()> { let title_style = ansi_term::Style::new().bold(); let writer = output_type.handle().unwrap(); - for theme in &get_themes() { + for theme in &get_themes(git_config::GitConfig::try_create()) { writeln!(writer, "\n\nTheme: {}\n", title_style.paint(theme))?; let opt = cli::Opt::from_iter_and_git_config(&["", "", "--features", &theme], &mut git_config); diff --git a/src/options/get.rs b/src/options/get.rs index a36987ca..58209f5d 100644 --- a/src/options/get.rs +++ b/src/options/get.rs @@ -1,3 +1,5 @@ +use lazy_static::lazy_static; +use regex::Regex; use std::collections::HashMap; use crate::cli; @@ -38,6 +40,28 @@ where T::get_option_value(option_name, builtin_features, opt, git_config) } +lazy_static! { + static ref GIT_CONFIG_THEME_REGEX: Regex = Regex::new(r"^delta\.(.+)\.is-theme$").unwrap(); +} + +pub fn get_themes(git_config: Option) -> Vec { + let mut themes: Vec = Vec::new(); + for e in &git_config.unwrap().config.entries(None).unwrap() { + let entry = e.unwrap(); + let entry_name = entry.name().unwrap(); + let entry_value = entry.value().unwrap(); + if entry_value == "true" { + let caps = GIT_CONFIG_THEME_REGEX.captures(entry_name); + if let Some(caps) = caps { + // need to check value i.e. whether is_theme = false + let name = caps.get(1).map_or("", |m| m.as_str()).to_string(); + themes.push(name) + } + } + } + themes +} + pub trait GetOptionValue { fn get_option_value( option_name: &str, @@ -115,6 +139,7 @@ pub mod tests { use std::env; use std::fs::remove_file; + use crate::options::get::get_themes; use crate::tests::integration_test_utils::integration_test_utils; // TODO: the followig tests are collapsed into one since they all set the same env var and thus @@ -275,4 +300,33 @@ pub mod tests { remove_file(git_config_path).unwrap(); } + + #[test] + fn test_get_themes_from_config() { + let git_config_contents = b" +[delta \"yes\"] + max-line-distance = 0.6 + is-theme = true + +[delta \"not-a-theme\"] + max-line-distance = 0.6 + is-theme = false + +[delta \"has-no-theme-entry\"] + max-line-distance = 0.6 +"; + let git_config_path = "delta__test_get_themes_git_config.gitconfig"; + + let git_config = Some(integration_test_utils::make_git_config( + git_config_contents, + git_config_path, + false, + )); + + let themes = get_themes(git_config); + + assert_eq!(themes, ["yes"]); + + remove_file(git_config_path).unwrap(); + } } diff --git a/src/tests/integration_test_utils.rs b/src/tests/integration_test_utils.rs index 8eb36748..1fdb215a 100644 --- a/src/tests/integration_test_utils.rs +++ b/src/tests/integration_test_utils.rs @@ -69,7 +69,7 @@ pub mod integration_test_utils { config::Config::from(make_options_from_args(args)) } - fn make_git_config(contents: &[u8], path: &str, honor_env_var: bool) -> GitConfig { + pub fn make_git_config(contents: &[u8], path: &str, honor_env_var: bool) -> GitConfig { let path = Path::new(path); let mut file = File::create(path).unwrap(); file.write_all(contents).unwrap(); -- cgit v1.2.3 From d83c438597d29b60c7a4236417e12fa52e67c78c Mon Sep 17 00:00:00 2001 From: Catherine Noll Date: Sat, 27 Mar 2021 21:16:40 -0400 Subject: Define theme by presence of "dark" or "light" entries in git config, and give the ability to filter themes shown with --show-themes by dark or light, using the --dark and --light flags --- src/cli.rs | 4 ++++ src/main.rs | 22 ++++++++++++++-------- src/options/get.rs | 27 ++++++++++++++++++--------- themes.gitconfig | 7 +++---- 4 files changed, 39 insertions(+), 21 deletions(-) diff --git a/src/cli.rs b/src/cli.rs index 781fd644..60a4d5a7 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -201,11 +201,13 @@ https://github.com/dandavison/delta/issues. pub struct Opt { /// Use default colors appropriate for a light terminal background. For more control, see the /// style options and --syntax-theme. + /// When passed in with --show-themes, only light themes will be displayed. #[structopt(long = "light")] pub light: bool, /// Use default colors appropriate for a dark terminal background. For more control, see the /// style options and --syntax-theme. + /// When passed in with --show-themes, only dark themes will be displayed. #[structopt(long = "dark")] pub dark: bool, @@ -272,6 +274,8 @@ pub struct Opt { /// Show all available delta themes, each with an example of highlighted diff output. /// If diff output is supplied on standard input then this will be used for the demo. For /// example: `git show --color=always | delta --show-themes`. + /// When used with the --dark or --light command line arguments, will only show dark or + /// light themes, respectively. #[structopt(long = "show-themes")] pub show_themes: bool, diff --git a/src/main.rs b/src/main.rs index fb4628ed..dcc6ed48 100644 --- a/src/main.rs +++ b/src/main.rs @@ -68,7 +68,7 @@ fn run_app() -> std::io::Result { show_syntax_themes()?; return Ok(0); } else if opt.show_themes { - show_themes()?; + show_themes(opt.dark, opt.light)?; return Ok(0); } @@ -312,7 +312,7 @@ where } } -fn show_themes() -> std::io::Result<()> { +fn show_themes(dark: bool, light: bool) -> std::io::Result<()> { use bytelines::ByteLines; use sample_diff::DIFF; use std::io::BufReader; @@ -337,17 +337,23 @@ fn show_themes() -> std::io::Result<()> { let writer = output_type.handle().unwrap(); for theme in &get_themes(git_config::GitConfig::try_create()) { - writeln!(writer, "\n\nTheme: {}\n", title_style.paint(theme))?; let opt = cli::Opt::from_iter_and_git_config(&["", "", "--features", &theme], &mut git_config); + let is_dark_theme = opt.dark; + let is_light_theme = opt.light; let config = config::Config::from(opt); - if let Err(error) = delta(ByteLines::new(BufReader::new(&input[0..])), writer, &config) { - match error.kind() { - ErrorKind::BrokenPipe => process::exit(0), - _ => eprintln!("{}", error), + if (dark && is_dark_theme) || (light && is_light_theme) || (!dark && !light) { + writeln!(writer, "\n\nTheme: {}\n", title_style.paint(theme))?; + + if let Err(error) = delta(ByteLines::new(BufReader::new(&input[0..])), writer, &config) + { + match error.kind() { + ErrorKind::BrokenPipe => process::exit(0), + _ => eprintln!("{}", error), + } } - }; + } } Ok(()) diff --git a/src/options/get.rs b/src/options/get.rs index 58209f5d..a1bbecae 100644 --- a/src/options/get.rs +++ b/src/options/get.rs @@ -41,7 +41,7 @@ where } lazy_static! { - static ref GIT_CONFIG_THEME_REGEX: Regex = Regex::new(r"^delta\.(.+)\.is-theme$").unwrap(); + static ref GIT_CONFIG_THEME_REGEX: Regex = Regex::new(r"^delta\.(.+)\.(light|dark)$").unwrap(); } pub fn get_themes(git_config: Option) -> Vec { @@ -53,9 +53,10 @@ pub fn get_themes(git_config: Option) -> Vec { if entry_value == "true" { let caps = GIT_CONFIG_THEME_REGEX.captures(entry_name); if let Some(caps) = caps { - // need to check value i.e. whether is_theme = false let name = caps.get(1).map_or("", |m| m.as_str()).to_string(); - themes.push(name) + if !themes.contains(&name) { + themes.push(name) + } } } } @@ -304,15 +305,20 @@ pub mod tests { #[test] fn test_get_themes_from_config() { let git_config_contents = b" -[delta \"yes\"] +[delta \"dark-theme\"] max-line-distance = 0.6 - is-theme = true + dark = true -[delta \"not-a-theme\"] +[delta \"light-theme\"] + max-line-distance = 0.6 + light = true + +[delta \"light-and-dark-theme\"] max-line-distance = 0.6 - is-theme = false + light = true + dark = true -[delta \"has-no-theme-entry\"] +[delta \"not-a-theme\"] max-line-distance = 0.6 "; let git_config_path = "delta__test_get_themes_git_config.gitconfig"; @@ -325,7 +331,10 @@ pub mod tests { let themes = get_themes(git_config); - assert_eq!(themes, ["yes"]); + assert_eq!( + themes, + ["dark-theme", "light-theme", "light-and-dark-theme"] + ); remove_file(git_config_path).unwrap(); } diff --git a/themes.gitconfig b/themes.gitconfig index 3dd4ba1a..68783e9c 100644 --- a/themes.gitconfig +++ b/themes.gitconfig @@ -49,10 +49,10 @@ file-modified-label = [M] file-removed-label = [-] file-renamed-label = [R] - is-theme = true [delta "villsau"] # author: https://github.com/torarnv + dark = true syntax-theme = OneHalfDark line-numbers = false hunk-header-style = file line-number syntax @@ -70,11 +70,11 @@ plus-emph-style = bold green 22 plus-empty-line-marker-style = normal "#002800" whitespace-error-style = reverse red - is-theme = true [delta "collared-trogon"] # author: https://github.com/clnoll commit-decoration-style = bold box ul + dark = true file-style = omit file-decoration-style = none hunk-header-style = file line-number syntax @@ -92,11 +92,11 @@ plus-style = syntax "#001a00" plus-emph-style = syntax "#003300" syntax-theme = Nord - is-theme = true [delta "tangara-chilensis"] # author: https://github.com/clnoll commit-decoration-style = bold box ul "#34fd50" + dark = true file-style = omit file-decoration-style = none hunk-header-style = file line-number syntax @@ -115,4 +115,3 @@ plus-emph-style = syntax "#03a4ff" side-by-side = true syntax-theme = Vibrant Sunburst - is-theme = true -- cgit v1.2.3 From 4aaa5f2848e5effcbd0938af374a64a39ab53ae3 Mon Sep 17 00:00:00 2001 From: Catherine Noll Date: Sat, 27 Mar 2021 22:09:48 -0400 Subject: Update behavior of --show-themes to rely on the computed is_light_mode value to determine whether to show light or dark themes by default --- src/cli.rs | 10 +++++----- src/main.rs | 9 ++++++--- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/cli.rs b/src/cli.rs index 60a4d5a7..e90c26d7 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -201,13 +201,11 @@ https://github.com/dandavison/delta/issues. pub struct Opt { /// Use default colors appropriate for a light terminal background. For more control, see the /// style options and --syntax-theme. - /// When passed in with --show-themes, only light themes will be displayed. #[structopt(long = "light")] pub light: bool, /// Use default colors appropriate for a dark terminal background. For more control, see the /// style options and --syntax-theme. - /// When passed in with --show-themes, only dark themes will be displayed. #[structopt(long = "dark")] pub dark: bool, @@ -271,11 +269,13 @@ pub struct Opt { #[structopt(long = "show-syntax-themes")] pub show_syntax_themes: bool, - /// Show all available delta themes, each with an example of highlighted diff output. + /// Show available delta themes with an example of highlighted diff output. /// If diff output is supplied on standard input then this will be used for the demo. For /// example: `git show --color=always | delta --show-themes`. - /// When used with the --dark or --light command line arguments, will only show dark or - /// light themes, respectively. + /// By default, if delta is configured to use a light theme (as set by the user or inferred by the + /// BAT_THEME), only displays light themes, otherwise will only display dark themes, unless the + /// --dark or --light command line arguments are included. + /// If both --dark and --light command line arguments are included, will display all themes. #[structopt(long = "show-themes")] pub show_themes: bool, diff --git a/src/main.rs b/src/main.rs index dcc6ed48..c99fb464 100644 --- a/src/main.rs +++ b/src/main.rs @@ -68,7 +68,7 @@ fn run_app() -> std::io::Result { show_syntax_themes()?; return Ok(0); } else if opt.show_themes { - show_themes(opt.dark, opt.light)?; + show_themes(opt.dark, opt.light, opt.computed.is_light_mode)?; return Ok(0); } @@ -312,7 +312,7 @@ where } } -fn show_themes(dark: bool, light: bool) -> std::io::Result<()> { +fn show_themes(dark: bool, light: bool, computed_theme_is_light: bool) -> std::io::Result<()> { use bytelines::ByteLines; use sample_diff::DIFF; use std::io::BufReader; @@ -343,7 +343,10 @@ fn show_themes(dark: bool, light: bool) -> std::io::Result<()> { let is_light_theme = opt.light; let config = config::Config::from(opt); - if (dark && is_dark_theme) || (light && is_light_theme) || (!dark && !light) { + if (!computed_theme_is_light && is_dark_theme) + || (computed_theme_is_light && is_light_theme) + || (dark && light) + { writeln!(writer, "\n\nTheme: {}\n", title_style.paint(theme))?; if let Err(error) = delta(ByteLines::new(BufReader::new(&input[0..])), writer, &config) -- cgit v1.2.3 From 2e02bbec383d719a83c5a5193e7f8cd1e07cae12 Mon Sep 17 00:00:00 2001 From: Catherine Noll Date: Sat, 27 Mar 2021 22:13:14 -0400 Subject: Fix typo in docstring --- src/options/theme.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/options/theme.rs b/src/options/theme.rs index ae831202..420c5be5 100644 --- a/src/options/theme.rs +++ b/src/options/theme.rs @@ -66,7 +66,7 @@ fn is_no_syntax_highlighting_syntax_theme_name(theme_name: &str) -> bool { /// chosen for a light or dark terminal background. (`bat` has no equivalent.) /// /// Basically: -/// 1. The theme is specified by the `--theme` option. If this isn't supplied then it is specified +/// 1. The theme is specified by the `--syntax-theme` option. If this isn't supplied then it is specified /// by the `BAT_THEME` environment variable. /// 2. Light vs dark mode is specified by the `--light` or `--dark` options. If these aren't /// supplied then it is inferred from the chosen theme. -- cgit v1.2.3 From 6dd4209e75252cb28563a618ec91285d97a07cd6 Mon Sep 17 00:00:00 2001 From: Catherine Noll Date: Sat, 27 Mar 2021 22:25:11 -0400 Subject: Remove unnecessary check in get_themes and clean up --show-themes cli docstring --- src/cli.rs | 2 +- src/options/get.rs | 13 +++++-------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/cli.rs b/src/cli.rs index e90c26d7..a771ad53 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -271,7 +271,7 @@ pub struct Opt { /// Show available delta themes with an example of highlighted diff output. /// If diff output is supplied on standard input then this will be used for the demo. For - /// example: `git show --color=always | delta --show-themes`. + /// example: `git show | delta --show-themes`. /// By default, if delta is configured to use a light theme (as set by the user or inferred by the /// BAT_THEME), only displays light themes, otherwise will only display dark themes, unless the /// --dark or --light command line arguments are included. diff --git a/src/options/get.rs b/src/options/get.rs index a1bbecae..5752283a 100644 --- a/src/options/get.rs +++ b/src/options/get.rs @@ -49,14 +49,11 @@ pub fn get_themes(git_config: Option) -> Vec { for e in &git_config.unwrap().config.entries(None).unwrap() { let entry = e.unwrap(); let entry_name = entry.name().unwrap(); - let entry_value = entry.value().unwrap(); - if entry_value == "true" { - let caps = GIT_CONFIG_THEME_REGEX.captures(entry_name); - if let Some(caps) = caps { - let name = caps.get(1).map_or("", |m| m.as_str()).to_string(); - if !themes.contains(&name) { - themes.push(name) - } + let caps = GIT_CONFIG_THEME_REGEX.captures(entry_name); + if let Some(caps) = caps { + let name = caps.get(1).map_or("", |m| m.as_str()).to_string(); + if !themes.contains(&name) { + themes.push(name) } } } -- cgit v1.2.3 From ebb05c7e677d8a3148aa5543b4fd780ae7429eb6 Mon Sep 17 00:00:00 2001 From: Catherine Noll Date: Sun, 28 Mar 2021 00:22:11 -0400 Subject: Use string literal instead of escaping double quotes --- src/options/get.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/options/get.rs b/src/options/get.rs index 5752283a..6542fd8e 100644 --- a/src/options/get.rs +++ b/src/options/get.rs @@ -301,27 +301,27 @@ pub mod tests { #[test] fn test_get_themes_from_config() { - let git_config_contents = b" -[delta \"dark-theme\"] + let git_config_contents = r#" +[delta "dark-theme"] max-line-distance = 0.6 dark = true -[delta \"light-theme\"] +[delta "light-theme"] max-line-distance = 0.6 light = true -[delta \"light-and-dark-theme\"] +[delta "light-and-dark-theme"] max-line-distance = 0.6 light = true dark = true -[delta \"not-a-theme\"] +[delta "not-a-theme"] max-line-distance = 0.6 -"; +"#; let git_config_path = "delta__test_get_themes_git_config.gitconfig"; let git_config = Some(integration_test_utils::make_git_config( - git_config_contents, + git_config_contents.as_bytes(), git_config_path, false, )); -- cgit v1.2.3 From cef38eef5ac6b8e9f84d55d5e01a92a366cd8e3a Mon Sep 17 00:00:00 2001 From: Dan Davison Date: Sun, 28 Mar 2021 09:46:42 -0400 Subject: Edit --help text --- src/cli.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/cli.rs b/src/cli.rs index a771ad53..2f2ac386 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -265,17 +265,17 @@ pub struct Opt { /// Show all available syntax-highlighting themes, each with an example of highlighted diff output. /// If diff output is supplied on standard input then this will be used for the demo. For - /// example: `git show --color=always | delta --show-syntax-themes`. + /// example: `git show | delta --show-syntax-themes`. #[structopt(long = "show-syntax-themes")] pub show_syntax_themes: bool, - /// Show available delta themes with an example of highlighted diff output. - /// If diff output is supplied on standard input then this will be used for the demo. For - /// example: `git show | delta --show-themes`. - /// By default, if delta is configured to use a light theme (as set by the user or inferred by the - /// BAT_THEME), only displays light themes, otherwise will only display dark themes, unless the - /// --dark or --light command line arguments are included. - /// If both --dark and --light command line arguments are included, will display all themes. + /// Show available delta themes, each with an example of highlighted diff output. A delta theme + /// is a delta named feature (see --features) that sets either `light` or `dark`. If diff + /// output is supplied on standard input then this will be used for the demo. For example: `git + /// show | delta --show-themes`. By default shows dark or light themes only, according to + /// whether delta is in dark or light mode (as set by the user or inferred from BAT_THEME). To + /// control the themes shown, use --dark or --light, or both, on the command line together with + /// this option. #[structopt(long = "show-themes")] pub show_themes: bool, -- cgit v1.2.3 From fb77406bf0294ab405d57594e955524db6f469be Mon Sep 17 00:00:00 2001 From: Dan Davison Date: Sun, 28 Mar 2021 10:04:14 -0400 Subject: Edit instructions in themes.gitconfig --- themes.gitconfig | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/themes.gitconfig b/themes.gitconfig index 68783e9c..c549a3a9 100644 --- a/themes.gitconfig +++ b/themes.gitconfig @@ -14,8 +14,9 @@ # organism: mammal, bird, plant, mollusk -- whatever. It can be in # any language. # -# 2. Please include a comment line describing the terminal -# theme/colors that you typically use with this theme. +# 2. Include either `dark = true` or `light = true` according to whether you feel +# it looks best on a dark or light terminal background. (This marks a feature +# as a "theme", causing it to be picked up by `delta --show-themes`). # # 3. Feel free to include a comment line indicating who is the author # of the theme. E.g. a link to your github user page. -- cgit v1.2.3 From 8353527d5b08d7ef5f531337b3d6d1b8ed291ff0 Mon Sep 17 00:00:00 2001 From: Catherine Noll Date: Sun, 28 Mar 2021 21:27:25 -0400 Subject: Display themes alphabetically when using --show-themes --- src/options/get.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/options/get.rs b/src/options/get.rs index 6542fd8e..b907ee88 100644 --- a/src/options/get.rs +++ b/src/options/get.rs @@ -57,6 +57,7 @@ pub fn get_themes(git_config: Option) -> Vec { } } } + themes.sort_by(|a, b| a.to_lowercase().cmp(&b.to_lowercase())); themes } @@ -330,7 +331,7 @@ pub mod tests { assert_eq!( themes, - ["dark-theme", "light-theme", "light-and-dark-theme"] + ["dark-theme", "light-and-dark-theme", "light-theme",] ); remove_file(git_config_path).unwrap(); -- cgit v1.2.3 From 4b955f3f91f6bfaffdaaebafe58c54db3694be06 Mon Sep 17 00:00:00 2001 From: Catherine Noll Date: Sun, 28 Mar 2021 21:39:21 -0400 Subject: Update default diff used by --show-themes (to https://github.com/vuejs/vue/commit/7ec4627902020cccd7b3f4fbc63e1b0d6b9798cd) --- src/sample_diff.rs | 315 ++++++++++++++++------------------------------------- 1 file changed, 92 insertions(+), 223 deletions(-) diff --git a/src/sample_diff.rs b/src/sample_diff.rs index 2481f8d3..90de4262 100644 --- a/src/sample_diff.rs +++ b/src/sample_diff.rs @@ -1,224 +1,93 @@ -pub const DIFF: &[u8; 8715] = b"\ -commit dc267979a46caee4d79ed2e3d17af9bd513c4e39 -Author: Dan Davison -Date: Fri Jan 8 10:33:55 2021 -0500 - - Prevent tests setting env vars from affecting other tests - -diff --git a/src/git_config/git_config.rs b/src/git_config/git_config.rs -index 9620960..d95a6b1 100644 ---- a/src/git_config/git_config.rs -+++ b/src/git_config/git_config.rs -@@ -42,10 +42,14 @@ impl GitConfig { +pub const DIFF: &[u8] = r#" +commit 7ec4627902020cccd7b3f4fbc63e1b0d6b9798cd +Author: Evan You +Date: Thu Feb 21 08:52:15 2019 -0500 + + fix: ensure generated scoped slot code is compatible with 2.5 + + fix #9545 + +diff --git a/src/compiler/codegen/index.js b/src/compiler/codegen/index.js +index a64c3421..d433f756 100644 +--- a/src/compiler/codegen/index.js ++++ b/src/compiler/codegen/index.js +@@ -409,9 +409,9 @@ function genScopedSlots ( + .join(',') + + return `scopedSlots:_u([${generatedSlots}]${ +- needsForceUpdate ? `,true` : `` ++ needsForceUpdate ? `,null,true` : `` + }${ +- !needsForceUpdate && needsKey ? `,false,${hash(generatedSlots)}` : `` ++ !needsForceUpdate && needsKey ? `,null,false,${hash(generatedSlots)}` : `` + })` + } + +diff --git a/src/core/instance/render-helpers/resolve-scoped-slots.js b/src/core/instance/render-helpers/resolve-scoped-slots.js +index 6439324b..f11ca000 100644 +--- a/src/core/instance/render-helpers/resolve-scoped-slots.js ++++ b/src/core/instance/render-helpers/resolve-scoped-slots.js +@@ -2,15 +2,16 @@ + + export function resolveScopedSlots ( + fns: ScopedSlotsData, // see flow/vnode +- hasDynamicKeys: boolean, +- contentHashKey: number, +- res?: Object ++ res?: Object, ++ // the following are added in 2.6 ++ hasDynamicKeys?: boolean, ++ contentHashKey?: number + ): { [key: string]: Function, $stable: boolean } { + res = res || { $stable: !hasDynamicKeys } + for (let i = 0; i < fns.length; i++) { + const slot = fns[i] + if (Array.isArray(slot)) { +- resolveScopedSlots(slot, hasDynamicKeys, null, res) ++ resolveScopedSlots(slot, res, hasDynamicKeys) + } else if (slot) { + // marker for reverse proxying v-slot without scope on this.$slots + if (slot.proxy) { +@@ -20,7 +21,7 @@ export function resolveScopedSlots ( } - - #[cfg(test)] -- pub fn from_path(path: &Path) -> Self { -+ pub fn from_path(path: &Path, honor_env_var: bool) -> Self { - Self { - config: git2::Config::open(path).unwrap(), -- config_from_env_var: parse_config_from_env_var(), -+ config_from_env_var: if honor_env_var { -+ parse_config_from_env_var() -+ } else { -+ HashMap::new() -+ }, - repo: None, - enabled: true, - } -diff --git a/src/options/get.rs b/src/options/get.rs -index f19c329..a36987c 100644 ---- a/src/options/get.rs -+++ b/src/options/get.rs -@@ -117,8 +117,13 @@ pub mod tests { - - use crate::tests::integration_test_utils::integration_test_utils; - -+ // TODO: the followig tests are collapsed into one since they all set the same env var and thus -+ // could affect each other if allowed to run concurrently. -+ - #[test] -- fn test_simple_string_env_var_overrides_git_config() { -+ fn test_env_var_overrides_git_config() { -+ // ---------------------------------------------------------------------------------------- -+ // simple string - let git_config_contents = b\" - [delta] - plus-style = blue -@@ -133,7 +138,7 @@ pub mod tests { - assert_eq!(opt.plus_style, \"blue\"); - - env::set_var(\"GIT_CONFIG_PARAMETERS\", \"'delta.plus-style=green'\"); -- let opt = integration_test_utils::make_options_from_args_and_git_config( -+ let opt = integration_test_utils::make_options_from_args_and_git_config_honoring_env_var( - &[], - Some(git_config_contents), - Some(git_config_path), -@@ -141,10 +146,9 @@ pub mod tests { - assert_eq!(opt.plus_style, \"green\"); - - remove_file(git_config_path).unwrap(); -- } - -- #[test] -- fn test_complex_string_env_var_overrides_git_config() { -+ // ---------------------------------------------------------------------------------------- -+ // complex string - let git_config_contents = br##\" - [delta] - minus-style = red bold ul \"#ffeeee\" -@@ -162,7 +166,7 @@ pub mod tests { - \"GIT_CONFIG_PARAMETERS\", - r##\"'delta.minus-style=magenta italic ol \"#aabbcc\"'\"##, - ); -- let opt = integration_test_utils::make_options_from_args_and_git_config( -+ let opt = integration_test_utils::make_options_from_args_and_git_config_honoring_env_var( - &[], - Some(git_config_contents), - Some(git_config_path), -@@ -170,10 +174,9 @@ pub mod tests { - assert_eq!(opt.minus_style, r##\"magenta italic ol \"#aabbcc\"\"##,); - - remove_file(git_config_path).unwrap(); -- } - -- #[test] -- fn test_option_string_env_var_overrides_git_config() { -+ // ---------------------------------------------------------------------------------------- -+ // option string - let git_config_contents = b\" - [delta] - plus-style = blue -@@ -188,7 +191,7 @@ pub mod tests { - assert_eq!(opt.plus_style, \"blue\"); - - env::set_var(\"GIT_CONFIG_PARAMETERS\", \"'delta.plus-style=green'\"); -- let opt = integration_test_utils::make_options_from_args_and_git_config( -+ let opt = integration_test_utils::make_options_from_args_and_git_config_honoring_env_var( - &[], - Some(git_config_contents), - Some(git_config_path), -@@ -196,10 +199,9 @@ pub mod tests { - assert_eq!(opt.plus_style, \"green\"); - - remove_file(git_config_path).unwrap(); -- } - -- #[test] -- fn test_bool_env_var_overrides_git_config() { -+ // ---------------------------------------------------------------------------------------- -+ // bool - let git_config_contents = b\" - [delta] - side-by-side = true -@@ -214,7 +216,7 @@ pub mod tests { - assert_eq!(opt.side_by_side, true); - - env::set_var(\"GIT_CONFIG_PARAMETERS\", \"'delta.side-by-side=false'\"); -- let opt = integration_test_utils::make_options_from_args_and_git_config( -+ let opt = integration_test_utils::make_options_from_args_and_git_config_honoring_env_var( - &[], - Some(git_config_contents), - Some(git_config_path), -@@ -222,10 +224,9 @@ pub mod tests { - assert_eq!(opt.side_by_side, false); - - remove_file(git_config_path).unwrap(); -- } - -- #[test] -- fn test_int_env_var_overrides_git_config() { -+ // ---------------------------------------------------------------------------------------- -+ // int - let git_config_contents = b\" - [delta] - max-line-length = 1 -@@ -240,7 +241,7 @@ pub mod tests { - assert_eq!(opt.max_line_length, 1); - - env::set_var(\"GIT_CONFIG_PARAMETERS\", \"'delta.max-line-length=2'\"); -- let opt = integration_test_utils::make_options_from_args_and_git_config( -+ let opt = integration_test_utils::make_options_from_args_and_git_config_honoring_env_var( - &[], - Some(git_config_contents), - Some(git_config_path), -@@ -248,17 +249,16 @@ pub mod tests { - assert_eq!(opt.max_line_length, 2); - - remove_file(git_config_path).unwrap(); -- } - -- #[test] -- fn test_float_env_var_overrides_git_config() { -+ // ---------------------------------------------------------------------------------------- -+ // float - let git_config_contents = b\" - [delta] - max-line-distance = 0.6 - \"; - let git_config_path = \"delta__test_float_env_var_overrides_git_config.gitconfig\"; - -- let opt = integration_test_utils::make_options_from_args_and_git_config( -+ let opt = integration_test_utils::make_options_from_args_and_git_config_honoring_env_var( - &[], - Some(git_config_contents), - Some(git_config_path), -@@ -266,7 +266,7 @@ pub mod tests { - assert_eq!(opt.max_line_distance, 0.6); - - env::set_var(\"GIT_CONFIG_PARAMETERS\", \"'delta.max-line-distance=0.7'\"); -- let opt = integration_test_utils::make_options_from_args_and_git_config( -+ let op