mirror of
https://github.com/dandavison/delta.git
synced 2024-10-04 20:07:18 +03:00
blame-separator and blame-separator-style options
This commit is contained in:
parent
76905c8e87
commit
62ca45953f
11
src/cli.rs
11
src/cli.rs
@ -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
|
||||
|
@ -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,
|
||||
|
@ -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
|
||||
|
@ -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,
|
||||
|
@ -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([
|
||||
(
|
||||
|
Loading…
Reference in New Issue
Block a user