From 5dc0d6ef7e37a565b06d794b50fcc763079f9ed7 Mon Sep 17 00:00:00 2001 From: Dan Davison Date: Mon, 22 Nov 2021 20:15:06 -0500 Subject: 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 --- src/cli.rs | 6 ++ src/config.rs | 26 ++++++++ src/options/set.rs | 1 + src/paint.rs | 151 ++++++++++++++++++++++++------------------- src/style.rs | 104 +++++++++++++++++++++++++++++ src/tests/ansi_test_utils.rs | 1 - 6 files changed, 222 insertions(+), 67 deletions(-) (limited to 'src') diff --git a/src/cli.rs b/src/cli.rs index bc928291..ec9b44cf 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='bold purple => red "#eeeeee", bold cyan => syntax "#eeeeee"' + 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 1c28d060..efe6adb0 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