diff options
-rw-r--r-- | src/cli.rs | 6 | ||||
-rw-r--r-- | src/config.rs | 17 | ||||
-rw-r--r-- | src/features/side_by_side_wrap.rs | 33 | ||||
-rw-r--r-- | src/options/set.rs | 1 |
4 files changed, 29 insertions, 28 deletions
@@ -399,6 +399,12 @@ pub struct Opt { /// (underline), 'ol' (overline), or the combination 'ul ol'. pub hunk_header_decoration_style: String, + #[structopt(long = "inline-hint-style", default_value = "blue")] + /// Style (foreground, background, attributes) for content added by delta to + /// the original diff such as special characters to highlight tabs, and the + /// wrap and prefix symbols used in side-by-side mode. See STYLES section. + pub inline_hint_style: String, + /// The regular expression used to decide what a word is for the within-line highlight /// algorithm. For less fine-grained matching than the default try --word-diff-regex="\S+" /// --max-line-distance=1.0 (this is more similar to `git --word-diff`). diff --git a/src/config.rs b/src/config.rs index f9630759..d114ef7c 100644 --- a/src/config.rs +++ b/src/config.rs @@ -19,7 +19,6 @@ use crate::features::side_by_side; use crate::features::side_by_side_wrap; use crate::git_config::GitConfigEntry; use crate::style::{self, Style}; -use crate::syntect_color; pub struct Config { pub available_terminal_width: usize, @@ -42,7 +41,7 @@ pub struct Config { pub hunk_header_style_include_line_number: bool, pub hyperlinks: bool, pub hyperlinks_file_link_format: String, - pub inline_hint_color: Option<SyntectStyle>, + pub inline_hint_style: Style, pub inspect_raw_lines: cli::InspectRawLines, pub keep_plus_minus_markers: bool, pub line_numbers: bool, @@ -162,6 +161,14 @@ impl From<cli::Opt> for Config { _ => *style::GIT_DEFAULT_PLUS_STYLE, }; + let inline_hint_style = Style::from_str( + &opt.inline_hint_style, + None, + None, + opt.computed.true_color, + false, + ); + let file_added_label = opt.file_added_label; let file_copied_label = opt.file_copied_label; let file_modified_label = opt.file_modified_label; @@ -209,12 +216,8 @@ impl From<cli::Opt> for Config { .any(|s| s == "line-number"), hyperlinks: opt.hyperlinks, hyperlinks_file_link_format: opt.hyperlinks_file_link_format, + inline_hint_style, inspect_raw_lines: opt.computed.inspect_raw_lines, - inline_hint_color: Some(SyntectStyle { - // TODO: color from theme? - foreground: syntect_color::syntect_color_from_ansi_name("blue").unwrap(), - ..SyntectStyle::default() - }), keep_plus_minus_markers: opt.keep_plus_minus_markers, line_numbers: opt.line_numbers, line_numbers_left_format: opt.line_numbers_left_format, diff --git a/src/features/side_by_side_wrap.rs b/src/features/side_by_side_wrap.rs index eb293da1..6f2f428f 100644 --- a/src/features/side_by_side_wrap.rs +++ b/src/features/side_by_side_wrap.rs @@ -35,7 +35,7 @@ pub fn wrap_line<'a, I, S>( line: I, line_width: usize, fill_style: &S, - inline_hint_style: &Option<S>, + inline_hint_style: &S, ) -> Vec<Vec<(S, &'a str)>> where I: IntoIterator<Item = (S, &'a str)> + std::fmt::Debug, @@ -61,12 +61,6 @@ where let mut curr_line = Vec::new(); let mut curr_len = 0; - // Determine the background (diff) and color (syntax) of an inserted symbol. - let symbol_style = match inline_hint_style { - Some(style) => *style, - None => *fill_style, - }; - let mut stack = line.into_iter().rev().collect::<Vec<_>>(); let line_limit_reached = |result: &Vec<_>| { @@ -138,7 +132,7 @@ where }; stack.push((style, next_line)); - curr_line.push((symbol_style, &wrap_config.wrap_symbol)); + curr_line.push((*inline_hint_style, &wrap_config.wrap_symbol)); result.push(curr_line); curr_line = vec![(S::default(), LINEPREFIX)]; @@ -181,7 +175,7 @@ where n => right_aligned_line.push((*fill_style, &SPACES[0..n])), } - right_aligned_line.push((symbol_style, &wrap_config.wrap_right_prefix_symbol)); + right_aligned_line.push((*inline_hint_style, &wrap_config.wrap_right_prefix_symbol)); // skip LINEPREFIX right_aligned_line.extend(curr_line.into_iter().skip(1)); @@ -213,7 +207,7 @@ fn wrap_if_too_long<'a, S>( must_wrap: bool, line_width: usize, fill_style: &S, - inline_hint_style: &Option<S>, + inline_hint_style: &S, ) -> (usize, usize) where S: Copy + Default + std::fmt::Debug, @@ -226,7 +220,7 @@ where input_vec.into_iter(), line_width, fill_style, - &inline_hint_style, + inline_hint_style, )); } else { wrapped.push(input_vec.to_vec()); @@ -294,7 +288,7 @@ pub fn wrap_plusminus_block<'c: 'a, 'a>( must_wrap, line_width, &SyntectStyle::default(), - &config.inline_hint_color, + &SyntectStyle::default(), ); let (start2, extended_to2) = wrap_if_too_long( @@ -306,7 +300,7 @@ pub fn wrap_plusminus_block<'c: 'a, 'a>( must_wrap, line_width, &fill_style, - &None, + &config.inline_hint_style, ); // The underlying text is the same for the style and diff, so @@ -458,19 +452,16 @@ pub fn wrap_zero_block<'c: 'a, 'a>( &config, syntax_style_sections.into_iter().flatten(), line_width, - &SyntectStyle::default(), - &config.inline_hint_color, + // We do not express any delta styling using the stream of syntax styles. + &config.null_syntect_style, + &config.null_syntect_style, ); let diff_style = wrap_line( &config, diff_style_sections.into_iter().flatten(), line_width, - // To actually highlight `config.inline_hint_color` characters: - &Style { - is_syntax_highlighted: true, - ..config.null_style - }, - &None, + &config.null_style, + &config.inline_hint_style, ); states.resize_with(syntax_style.len(), || State::HunkZeroWrapped); diff --git a/src/options/set.rs b/src/options/set.rs index 25febc0e..9096785f 100644 --- a/src/options/set.rs +++ b/src/options/set.rs @@ -140,6 +140,7 @@ pub fn set_options( hunk_header_style, hyperlinks, hyperlinks_file_link_format, + inline_hint_style, inspect_raw_lines, keep_plus_minus_markers, line_buffer_size, |