From 4d7bc443f144eb3c18b8354587d3d758b9763cb4 Mon Sep 17 00:00:00 2001 From: Dan Davison Date: Mon, 22 Nov 2021 20:15:06 -0500 Subject: [PATCH] New option to map raw styles encountered in input Unify handling of styles parsed from raw line and computed diff styles. This enables syntax highlighting to be used in color-moved sections. Fixes #72 --- etc/examples/72-color-moved-2.diff | 8 ++ src/cli.rs | 6 ++ src/config.rs | 26 ++++++ src/options/set.rs | 1 + src/paint.rs | 135 ++++++++++++++++------------- src/style.rs | 104 ++++++++++++++++++++++ 6 files changed, 221 insertions(+), 59 deletions(-) create mode 100644 etc/examples/72-color-moved-2.diff diff --git a/etc/examples/72-color-moved-2.diff b/etc/examples/72-color-moved-2.diff new file mode 100644 index 000000000..69ddc5c87 --- /dev/null +++ b/etc/examples/72-color-moved-2.diff @@ -0,0 +1,8 @@ +diff --git a/file.py b/file.py +index f07db74..3cb162d 100644 +--- a/file.py ++++ b/file.py +@@ -1,2 +1,2 @@ +-class X: pass + class Y: pass ++class X: pass diff --git a/src/cli.rs b/src/cli.rs index bc928291f..1691b7d38 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -429,6 +429,12 @@ pub struct Opt { /// (underline), 'ol' (overline), or the combination 'ul ol'. pub hunk_header_decoration_style: String, + #[structopt(long = "map-styles")] + /// A string specifying a mapping styles encountered in raw input to desired + /// output styles. An example is --map-styles='black cyan => white magenta, + /// red cyan => white blue' + pub map_styles: Option, + /// Format string for git blame commit metadata. Available placeholders are /// "{timestamp}", "{author}", and "{commit}". #[structopt( diff --git a/src/config.rs b/src/config.rs index 1c28d060c..efe6adb0b 100644 --- a/src/config.rs +++ b/src/config.rs @@ -20,6 +20,7 @@ use crate::git_config::{GitConfig, GitConfigEntry}; use crate::minusplus::MinusPlus; use crate::paint::BgFillMethod; use crate::parse_styles; +use crate::style; use crate::style::Style; use crate::tests::TESTING; use crate::utils::bat::output::PagingMode; @@ -105,6 +106,7 @@ pub struct Config { pub line_numbers_style_minusplus: MinusPlus