From a5c256f2e48c47a47f7a5ca5f131871b14efeb7f Mon Sep 17 00:00:00 2001 From: Thomas Otto Date: Tue, 4 Jan 2022 21:58:39 +0100 Subject: Show blame line numbers via blame-separator-format Prefix and suffix of the format string are separator_style highlighted, format options are none, {n}, {n:block}, {n:every-N}. --- src/cli.rs | 12 ++++-- src/config.rs | 6 ++- src/handlers/blame.rs | 111 +++++++++++++++++++++++++++++++++++++++++++++++++- src/options/set.rs | 2 +- 4 files changed, 123 insertions(+), 8 deletions(-) diff --git a/src/cli.rs b/src/cli.rs index dece275b..cc26d782 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -551,9 +551,15 @@ pub struct Opt { /// Available placeholders are "{timestamp}", "{author}", and "{commit}". pub blame_format: String, - #[clap(long = "blame-separator", default_value = "│")] - /// Separator between the commit metadata and code sections of a git blame line. - pub blame_separator: String, + /// Separator between the commit metadata and code sections of a line of git blame output. Contains + /// the line number by default. Possible values are "none" to disable line numbers or a format + /// string. This may contain one "{n:}" placeholder and will display the line number on every line. + /// A type may be added after all other format specifiers and can be separated by '_': + /// If type is set to 'block' (e.g. "{n:^4_block}") the line number will only be shown when a new blame + /// block starts; or if it is set to 'every-N' the line will be show with every block and every + /// N-th (modulo) line. + #[clap(long = "blame-separator-format", default_value = "│{n:^4}│")] + pub blame_separator_format: String, #[clap(long = "blame-separator-style")] /// Style string for the separator between the commit metadata and code sections of a git blame line. diff --git a/src/config.rs b/src/config.rs index 75bc7488..baddd084 100644 --- a/src/config.rs +++ b/src/config.rs @@ -17,6 +17,8 @@ use crate::features::navigate; use crate::features::side_by_side::{self, ansifill, LeftRight}; use crate::git_config::{GitConfig, GitConfigEntry}; use crate::handlers; +use crate::handlers::blame::parse_blame_line_numbers; +use crate::handlers::blame::BlameLineNumbers; use crate::minusplus::MinusPlus; use crate::paint::BgFillMethod; use crate::parse_styles; @@ -63,8 +65,8 @@ pub struct Config { pub background_color_extends_to_terminal_width: bool, pub blame_code_style: Option