summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Davison <dandavison7@gmail.com>2021-12-23 22:27:39 -0500
committerDan Davison <dandavison7@gmail.com>2021-12-24 07:40:45 -0500
commita1b8dbc410a1cdfa7341f091c95e8e89e46e28d0 (patch)
treeca12295ec34f2b2af3d9cd487840c4690dd3cecc
parent67124941d5212b6bf1ef12910419cfe1be5fada9 (diff)
New option blame-code-style
Fixes #867
-rw-r--r--src/cli.rs7
-rw-r--r--src/config.rs2
-rw-r--r--src/handlers/blame.rs2
-rw-r--r--src/options/set.rs1
-rw-r--r--src/parse_styles.rs13
5 files changed, 24 insertions, 1 deletions
diff --git a/src/cli.rs b/src/cli.rs
index ae93cacf..1b60bea5 100644
--- a/src/cli.rs
+++ b/src/cli.rs
@@ -495,6 +495,13 @@ pub struct Opt {
)]
pub blame_format: String,
+ #[structopt(long = "blame-code-style")]
+ /// Style (foreground, background, attributes) for the code section of a line of `git blame`
+ /// output. By default the code will be syntax-highlighted with the same background color as the
+ /// blame format section of the line (the background color is determined by blame-palette). E.g.
+ /// setting this option to 'syntax' will syntax-highlight the code with no background color.
+ pub blame_code_style: Option<String>,
+
/// Background colors used for git blame lines (space-separated string).
/// Lines added by the same commit are painted with the same color; colors
/// are recycled as needed.
diff --git a/src/config.rs b/src/config.rs
index d7798550..e8d991e4 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -60,6 +60,7 @@ fn adapt_wrap_max_lines_argument(arg: String) -> usize {
pub struct Config {
pub available_terminal_width: usize,
pub background_color_extends_to_terminal_width: bool,
+ pub blame_code_style: Option<Style>,
pub blame_format: String,
pub blame_palette: Vec<String>,
pub blame_timestamp_format: String,
@@ -241,6 +242,7 @@ impl From<cli::Opt> for Config {
.computed
.background_color_extends_to_terminal_width,
blame_format: opt.blame_format,
+ blame_code_style: styles.get("blame-code-style").copied(),
blame_palette,
blame_timestamp_format: opt.blame_timestamp_format,
commit_style: styles["commit-style"],
diff --git a/src/handlers/blame.rs b/src/handlers/blame.rs
index ec27ecda..e48f6ee7 100644
--- a/src/handlers/blame.rs
+++ b/src/handlers/blame.rs
@@ -100,7 +100,7 @@ impl<'a> StateMachine<'a> {
self.state = State::Blame(blame.commit.to_owned(), repeat_blame_line.to_owned());
self.painter.syntax_highlight_and_paint_line(
&format!("{}\n", blame.code),
- StyleSectionSpecifier::Style(style),
+ StyleSectionSpecifier::Style(self.config.blame_code_style.unwrap_or(style)),
self.state.clone(),
BgShouldFill::default(),
);
diff --git a/src/options/set.rs b/src/options/set.rs
index 8e7dd790..89a038a4 100644
--- a/src/options/set.rs
+++ b/src/options/set.rs
@@ -125,6 +125,7 @@ pub fn set_options(
set_options!(
[
+ blame_code_style,
blame_format,
blame_palette,
blame_timestamp_format,
diff --git a/src/parse_styles.rs b/src/parse_styles.rs
index fc8ad00a..a86fedcb 100644
--- a/src/parse_styles.rs
+++ b/src/parse_styles.rs
@@ -49,6 +49,19 @@ pub fn parse_styles(opt: &cli::Opt) -> HashMap<String, Style> {
_ => *style::GIT_DEFAULT_PLUS_STYLE,
}),
);
+ if let Some(style_string) = &opt.blame_code_style {
+ styles.insert(
+ "blame-code-style",
+ style_from_str(
+ style_string,
+ None,
+ None,
+ opt.computed.true_color,
+ opt.git_config.as_ref(),
+ ),
+ );
+ };
+
let mut resolved_styles = resolve_style_references(styles, opt);
resolved_styles.get_mut("minus-emph-style").unwrap().is_emph = true;
resolved_styles.get_mut("plus-emph-style").unwrap().is_emph = true;