From e2755af4f52e3c2b816a383241d0599f62becdca Mon Sep 17 00:00:00 2001 From: Dan Davison Date: Sun, 28 Nov 2021 19:43:57 -0500 Subject: [PATCH 1/3] Honor raw blame styles Fixes #808 --- src/handlers/blame.rs | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/src/handlers/blame.rs b/src/handlers/blame.rs index 629dc705e..c86271fd7 100644 --- a/src/handlers/blame.rs +++ b/src/handlers/blame.rs @@ -3,6 +3,7 @@ use lazy_static::lazy_static; use regex::Regex; use std::borrow::Cow; +use crate::ansi; use crate::ansi::measure_text_width; use crate::color; use crate::config; @@ -35,17 +36,27 @@ impl<'a> StateMachine<'a> { parse_git_blame_line(&self.line, &self.config.blame_timestamp_format) { let is_repeat = previous_commit == Some(blame.commit); - let color = self.get_color(blame.commit, previous_commit, is_repeat); - let mut style = Style::from_colors( - None, - color::parse_color(&color, true, self.config.git_config.as_ref()), - ); - // TODO: This will often be pointlessly updating a key with the - // value it already has. It might be nicer to do this (and - // compute the style) in get_color(), but as things stand the - // borrow checker won't permit that. - self.blame_commit_colors - .insert(blame.commit.to_owned(), color); + + let mut style = match ansi::parse_first_style(&self.raw_line) { + Some(ansi_term_style) => Style { + ansi_term_style, + ..Style::default() + }, + None => { + let color = self.get_color(blame.commit, previous_commit, is_repeat); + // TODO: This will often be pointlessly updating a key with the + // value it already has. It might be nicer to do this (and + // compute the style) in get_color(), but as things stand the + // borrow checker won't permit that. + let style = Style::from_colors( + None, + color::parse_color(&color, true, self.config.git_config.as_ref()), + ); + self.blame_commit_colors + .insert(blame.commit.to_owned(), color); + style + } + }; style.is_syntax_highlighted = true; From f4f8fb16106ddb7c041e0b11b93385aaeb5a444c Mon Sep 17 00:00:00 2001 From: Dan Davison Date: Sun, 28 Nov 2021 19:54:34 -0500 Subject: [PATCH 2/3] Honor map-styles --- src/handlers/blame.rs | 42 +++++++++++++++++++----------------------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/src/handlers/blame.rs b/src/handlers/blame.rs index c86271fd7..2b4a21448 100644 --- a/src/handlers/blame.rs +++ b/src/handlers/blame.rs @@ -3,15 +3,13 @@ use lazy_static::lazy_static; use regex::Regex; use std::borrow::Cow; -use crate::ansi; use crate::ansi::measure_text_width; use crate::color; use crate::config; use crate::config::delta_unreachable; use crate::delta::{self, State, StateMachine}; use crate::format::{self, Placeholder}; -use crate::paint::BgShouldFill; -use crate::paint::StyleSectionSpecifier; +use crate::paint::{self, BgShouldFill, StyleSectionSpecifier}; use crate::style::Style; use crate::utils; @@ -37,26 +35,24 @@ impl<'a> StateMachine<'a> { { let is_repeat = previous_commit == Some(blame.commit); - let mut style = match ansi::parse_first_style(&self.raw_line) { - Some(ansi_term_style) => Style { - ansi_term_style, - ..Style::default() - }, - None => { - let color = self.get_color(blame.commit, previous_commit, is_repeat); - // TODO: This will often be pointlessly updating a key with the - // value it already has. It might be nicer to do this (and - // compute the style) in get_color(), but as things stand the - // borrow checker won't permit that. - let style = Style::from_colors( - None, - color::parse_color(&color, true, self.config.git_config.as_ref()), - ); - self.blame_commit_colors - .insert(blame.commit.to_owned(), color); - style - } - }; + let mut style = + match paint::parse_style_sections(&self.raw_line, self.config).first() { + Some((style, _)) => *style, + None => { + let color = self.get_color(blame.commit, previous_commit, is_repeat); + // TODO: This will often be pointlessly updating a key with the + // value it already has. It might be nicer to do this (and + // compute the style) in get_color(), but as things stand the + // borrow checker won't permit that. + let style = Style::from_colors( + None, + color::parse_color(&color, true, self.config.git_config.as_ref()), + ); + self.blame_commit_colors + .insert(blame.commit.to_owned(), color); + style + } + }; style.is_syntax_highlighted = true; From 5fad15c325b1a806068a2a405ca385653cb64904 Mon Sep 17 00:00:00 2001 From: Dan Davison Date: Sun, 28 Nov 2021 19:58:37 -0500 Subject: [PATCH 3/3] Comments --- src/handlers/blame.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/handlers/blame.rs b/src/handlers/blame.rs index 2b4a21448..2cf6547f6 100644 --- a/src/handlers/blame.rs +++ b/src/handlers/blame.rs @@ -37,8 +37,13 @@ impl<'a> StateMachine<'a> { let mut style = match paint::parse_style_sections(&self.raw_line, self.config).first() { - Some((style, _)) => *style, + Some((style, _)) => { + // Something like `blame.coloring = highlightRecent` is in effect; honor + // the color from git, subject to map-styles. + *style + } None => { + // Compute the color ourselves. let color = self.get_color(blame.commit, previous_commit, is_repeat); // TODO: This will often be pointlessly updating a key with the // value it already has. It might be nicer to do this (and