diff options
author | Dan Davison <dandavison7@gmail.com> | 2021-12-26 22:01:24 -0500 |
---|---|---|
committer | Dan Davison <dandavison7@gmail.com> | 2021-12-28 12:16:43 +0000 |
commit | 62ca45953f5254a1b434725799d6e10ca63577fa (patch) | |
tree | 1844035115ea467785c674ebedf4334b095d1d56 | |
parent | 76905c8e8712e2ac06dbcc59f89bf0c3e41e7972 (diff) |
blame-separator and blame-separator-style options
-rw-r--r-- | src/cli.rs | 11 | ||||
-rw-r--r-- | src/config.rs | 8 | ||||
-rw-r--r-- | src/handlers/blame.rs | 4 | ||||
-rw-r--r-- | src/options/set.rs | 2 | ||||
-rw-r--r-- | src/parse_styles.rs | 28 |
5 files changed, 49 insertions, 4 deletions
@@ -491,10 +491,19 @@ pub struct Opt { /// "{timestamp}", "{author}", and "{commit}". #[structopt( long = "blame-format", - default_value = "{timestamp:<15} {author:<15.14} {commit:<8} │" + default_value = "{timestamp:<15} {author:<15.14} {commit:<8}" )] pub blame_format: String, + /// Separator between the commit metadata and code sections of a line of git blame output. + #[structopt(long = "blame-separator", default_value = "│")] + pub blame_separator: String, + + #[structopt(long = "blame-separator-style")] + /// Style (foreground, background, attributes) for the separator between the commit metadata and + /// code sections of a line of `git blame` output. + pub blame_separator_style: Option<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 diff --git a/src/config.rs b/src/config.rs index e8d991e4..be944cf2 100644 --- a/src/config.rs +++ b/src/config.rs @@ -63,6 +63,8 @@ pub struct Config { pub blame_code_style: Option<Style>, pub blame_format: String, pub blame_palette: Vec<String>, + pub blame_separator: String, + pub blame_separator_style: Option<Style>, pub blame_timestamp_format: String, pub color_only: bool, pub commit_regex: Regex, @@ -166,7 +168,7 @@ impl Config { impl From<cli::Opt> for Config { fn from(opt: cli::Opt) -> Self { - let styles = parse_styles::parse_styles(&opt); + let mut styles = parse_styles::parse_styles(&opt); let styles_map = parse_styles::parse_styles_map(&opt); let max_line_distance_for_naively_paired_lines = @@ -242,8 +244,10 @@ 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_code_style: styles.remove("blame-code-style"), blame_palette, + blame_separator: opt.blame_separator, + blame_separator_style: styles.remove("blame-separator-style"), blame_timestamp_format: opt.blame_timestamp_format, commit_style: styles["commit-style"], color_only: opt.color_only, diff --git a/src/handlers/blame.rs b/src/handlers/blame.rs index bc1be2ac..6687587a 100644 --- a/src/handlers/blame.rs +++ b/src/handlers/blame.rs @@ -47,11 +47,13 @@ impl<'a> StateMachine<'a> { let metadata_style = self.blame_metadata_style(&key, previous_key.as_deref(), is_repeat); let code_style = self.config.blame_code_style.unwrap_or(metadata_style); + let separator_style = self.config.blame_separator_style.unwrap_or(code_style); write!( self.painter.writer, - "{}", + "{}{}", metadata_style.paint(&formatted_blame_metadata), + separator_style.paint(&self.config.blame_separator) )?; // Emit syntax-highlighted code diff --git a/src/options/set.rs b/src/options/set.rs index 89a038a4..be3d74a1 100644 --- a/src/options/set.rs +++ b/src/options/set.rs @@ -128,6 +128,8 @@ pub fn set_options( blame_code_style, blame_format, blame_palette, + blame_separator, + blame_separator_style, blame_timestamp_format, color_only, commit_decoration_style, diff --git a/src/parse_styles.rs b/src/parse_styles.rs index eea3c11f..1bee9e54 100644 --- a/src/parse_styles.rs +++ b/src/parse_styles.rs @@ -22,6 +22,7 @@ pub fn parse_styles(opt: &cli::Opt) -> HashMap<String, Style> { make_hunk_styles(opt, &mut styles); make_commit_file_hunk_header_styles(opt, &mut styles); make_line_number_styles(opt, &mut styles); + make_blame_styles(opt, &mut styles); make_grep_styles(opt, &mut styles); make_merge_conflict_styles(opt, &mut styles); make_misc_styles(opt, &mut styles); @@ -360,6 +361,33 @@ fn make_commit_file_hunk_header_styles(opt: &cli::Opt, styles: &mut HashMap<&str ]); } +fn make_blame_styles(opt: &cli::Opt, styles: &mut HashMap<&str, StyleReference>) { + 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(), + ), + ); + }; + if let Some(style_string) = &opt.blame_separator_style { + styles.insert( + "blame-separator-style", + style_from_str( + style_string, + None, + None, + opt.computed.true_color, + opt.git_config.as_ref(), + ), + ); + }; +} + fn make_grep_styles(opt: &cli::Opt, styles: &mut HashMap<&str, StyleReference>) { styles.extend([ ( |