Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blame line numbers #885

Merged
merged 2 commits into from
Jan 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,12 +231,23 @@ pub struct Opt {
/// needed.
pub blame_palette: Option<String>,

#[clap(long = "blame-separator", default_value = "│", value_name = "STRING")]
/// Separator between the commit metadata and code sections of a git blame line.
pub blame_separator: String,
#[clap(
long = "blame-separator-format",
default_value = "│{n:^4}│",
value_name = "FMT"
)]
/// Separator between the blame format and the code section of a git blame line.
///
/// 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.
pub blame_separator_format: String,

#[clap(long = "blame-separator-style", value_name = "STYLE")]
/// Style string for the separator between the commit metadata and code sections of a git blame line.
/// Style string for the blame-separator-format.
pub blame_separator_style: Option<String>,

#[clap(
Expand Down
6 changes: 4 additions & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
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 @@ -258,7 +260,7 @@ 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_format: parse_blame_line_numbers(&opt.blame_separator_format),
blame_separator_style: styles.remove("blame-separator-style"),
blame_timestamp_format: opt.blame_timestamp_format,
commit_style: styles["commit-style"],
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