Skip to content
Closed
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
16 changes: 9 additions & 7 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,13 +230,15 @@ pub struct Opt {
/// needed.
pub blame_palette: Option<String>,

#[clap(
long = "blame-separator",
default_value = "│",
value_name = "SEPARATOR_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}│")]
/// 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.
pub blame_separator_format: String,

#[clap(long = "blame-separator-style", value_name = "STYLE_STRING")]
/// Style string for the separator between the commit metadata and code sections of a git blame line.
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 @@ -63,8 +65,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 @@ -248,7 +250,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
44 changes: 18 additions & 26 deletions src/features/line_numbers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,10 +261,7 @@ fn format_and_paint_line_number_field<'a>(
min_field_width
};

let alignment_spec = placeholder
.alignment_spec
.as_ref()
.unwrap_or(&Align::Center);
let alignment_spec = placeholder.alignment_spec.unwrap_or(Align::Center);
match placeholder.placeholder {
Some(Placeholder::NumberMinus) => {
ansi_strings.push(styles[Minus].paint(format_line_number(
Expand Down Expand Up @@ -298,20 +295,19 @@ fn format_and_paint_line_number_field<'a>(
/// Return line number formatted according to `alignment` and `width`.
fn format_line_number(
line_number: Option<usize>,
alignment: &Align,
alignment: Align,
width: usize,
precision: Option<usize>,
plus_file: Option<&str>,
config: &config::Config,
) -> String {
let pad = |n| format::pad(n, width, alignment, precision);
match (line_number, config.hyperlinks, plus_file) {
(None, _, _) => pad(""),
(None, _, _) => " ".repeat(width),
(Some(n), true, Some(file)) => {
hyperlinks::format_osc8_file_hyperlink(file, line_number, &pad(&n.to_string()), config)
.to_string()
hyperlinks::format_osc8_file_hyperlink(file, line_number, &pad(n), config).to_string()
}
(Some(n), _, _) => pad(&n.to_string()),
(Some(n), _, _) => pad(n),
}
}

Expand Down Expand Up @@ -339,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 @@ -358,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 @@ -376,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 @@ -392,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 @@ -413,6 +396,7 @@ pub mod tests {
suffix: "@@".into(),
prefix_len: 2,
suffix_len: 2,
..Default::default()
}]
)
}
Expand All @@ -431,6 +415,7 @@ pub mod tests {
suffix: "@@---{np:_>4}**".into(),
prefix_len: 2,
suffix_len: 15,
..Default::default()
},
format::FormatStringPlaceholderData {
prefix: "@@---".into(),
Expand All @@ -441,6 +426,7 @@ pub mod tests {
suffix: "**".into(),
prefix_len: 5,
suffix_len: 2,
..Default::default()
}
]
)
Expand All @@ -459,6 +445,7 @@ pub mod tests {
suffix: "__@@---**".into(),
prefix_len: 0,
suffix_len: 9,
..Default::default()
},]
)
}
Expand All @@ -476,6 +463,7 @@ pub mod tests {
suffix: "|".into(),
prefix_len: 2,
suffix_len: 1,
..Default::default()
}]
);
}
Expand All @@ -498,6 +486,7 @@ pub mod tests {
suffix: "+{np:<4}|".into(),
prefix_len: 2,
suffix_len: 9,
..Default::default()
},
format::FormatStringPlaceholderData {
prefix: "+".into(),
Expand All @@ -508,6 +497,7 @@ pub mod tests {
suffix: "|".into(),
prefix_len: 1,
suffix_len: 1,
..Default::default()
}
]
);
Expand All @@ -525,6 +515,7 @@ pub mod tests {
suffix: "|++|".into(),
prefix_len: 1,
suffix_len: 4,
..Default::default()
}]
);
}
Expand All @@ -547,6 +538,7 @@ pub mod tests {
precision: None,
suffix: long.into(),
suffix_len: long.len(),
..Default::default()
},]
)
}
Expand Down
Loading