Skip to content

Commit

Permalink
Show blame line numbers via blame-line-number-suffix
Browse files Browse the repository at this point in the history
Prefix and suffix of the format string are separator_style highlighted,
format options are off, {n}, {n:block}, {n:every-N}.

Add a FormatStringPlaceholderDataAnyPlaceholder template which works
without a borrowed Placeholder.
  • Loading branch information
th1000s committed Jan 13, 2022
1 parent 5a3eece commit b60ae7b
Show file tree
Hide file tree
Showing 6 changed files with 319 additions and 40 deletions.
11 changes: 8 additions & 3 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -499,9 +499,14 @@ pub struct Opt {
)]
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,
/// Separator between the commit metadata and code sections of a line of git blame output. Contains
/// the line number by default. Possible values are "off" to disable line numbers or a format
/// string. This may contain one "{n}" placeholder and will display the line number on every line.
/// If the type is given as block ("{n:block}") the line number will only be shown when a new blame
/// block starts; or if it is given as "{n:every-N}" the line will be show with every block and every
/// N-th (modulo) line.
#[structopt(long = "blame-separator-format", default_value = "│{n:^4}│")]
pub blame_separator_format: String,

#[structopt(long = "blame-separator-style")]
/// Style (foreground, background, attributes) for the separator between the commit metadata and
Expand Down
6 changes: 4 additions & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,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;
Expand Down Expand Up @@ -64,8 +66,8 @@ pub struct Config {
pub background_color_extends_to_terminal_width: bool,
pub blame_code_style: Option<Style>,
pub blame_format: String,
pub blame_separator_format: BlameLineNumbers,
pub blame_palette: Vec<String>,
pub blame_separator: String,
pub blame_separator_style: Option<Style>,
pub blame_timestamp_format: String,
pub color_only: bool,
Expand Down Expand Up @@ -249,9 +251,9 @@ impl From<cli::Opt> for Config {
blame_format: opt.blame_format,
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,
blame_separator_format: dbg!(parse_blame_line_numbers(&opt.blame_separator_format)),
commit_style: styles["commit-style"],
color_only: opt.color_only,
commit_regex,
Expand Down
30 changes: 13 additions & 17 deletions src/features/line_numbers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,12 +335,7 @@ pub mod tests {
vec![format::FormatStringPlaceholderData {
prefix: "".into(),
placeholder: Some(Placeholder::NumberMinus),
alignment_spec: None,
width: None,
precision: None,
suffix: "".into(),
prefix_len: 0,
suffix_len: 0,
..Default::default()
}]
)
}
Expand All @@ -354,10 +349,7 @@ pub mod tests {
placeholder: Some(Placeholder::NumberPlus),
alignment_spec: None,
width: Some(4),
precision: None,
suffix: "".into(),
prefix_len: 0,
suffix_len: 0,
..Default::default()
}]
)
}
Expand All @@ -372,9 +364,7 @@ pub mod tests {
alignment_spec: Some(Align::Right),
width: Some(4),
precision: None,
suffix: "".into(),
prefix_len: 0,
suffix_len: 0,
..Default::default()
}]
)
}
Expand All @@ -388,10 +378,7 @@ pub mod tests {
placeholder: Some(Placeholder::NumberPlus),
alignment_spec: Some(Align::Right),
width: Some(4),
precision: None,
suffix: "".into(),
prefix_len: 0,
suffix_len: 0,
..Default::default()
}]
)
}
Expand All @@ -409,6 +396,7 @@ pub mod tests {
suffix: "@@".into(),
prefix_len: 2,
suffix_len: 2,
..Default::default()
}]
)
}
Expand All @@ -427,6 +415,7 @@ pub mod tests {
suffix: "@@---{np:_>4}**".into(),
prefix_len: 2,
suffix_len: 15,
..Default::default()
},
format::FormatStringPlaceholderData {
prefix: "@@---".into(),
Expand All @@ -437,6 +426,7 @@ pub mod tests {
suffix: "**".into(),
prefix_len: 5,
suffix_len: 2,
..Default::default()
}
]
)
Expand All @@ -455,6 +445,7 @@ pub mod tests {
suffix: "__@@---**".into(),
prefix_len: 0,
suffix_len: 9,
..Default::default()
},]
)
}
Expand All @@ -472,6 +463,7 @@ pub mod tests {
suffix: "|".into(),
prefix_len: 2,
suffix_len: 1,
..Default::default()
}]
);
}
Expand All @@ -494,6 +486,7 @@ pub mod tests {
suffix: "+{np:<4}|".into(),
prefix_len: 2,
suffix_len: 9,
..Default::default()
},
format::FormatStringPlaceholderData {
prefix: "+".into(),
Expand All @@ -504,6 +497,7 @@ pub mod tests {
suffix: "|".into(),
prefix_len: 1,
suffix_len: 1,
..Default::default()
}
]
);
Expand All @@ -521,6 +515,7 @@ pub mod tests {
suffix: "|++|".into(),
prefix_len: 1,
suffix_len: 4,
..Default::default()
}]
);
}
Expand All @@ -543,6 +538,7 @@ pub mod tests {
precision: None,
suffix: long.into(),
suffix_len: long.len(),
..Default::default()
},]
)
}
Expand Down
Loading

0 comments on commit b60ae7b

Please sign in to comment.