Skip to content

Commit

Permalink
Alternative solution
Browse files Browse the repository at this point in the history
  • Loading branch information
hpwxf committed Jun 23, 2023
1 parent 70a9fd8 commit dc38ca9
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/handlers/blame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,21 +270,26 @@ pub fn format_blame_metadata(
let width = placeholder.width.unwrap_or(15);

let field = match placeholder.placeholder {
Some(Placeholder::Str("timestamp")) => {
Some(Cow::from(match &config.blame_timestamp_output_format {
Some(Placeholder::Str("timestamp")) => Some((
Cow::from(match &config.blame_timestamp_output_format {
Some(time_format) => blame.time.format(time_format).to_string(),
None => chrono_humanize::HumanTime::from(blame.time).to_string(),
}))
}),
0,
)),
Some(Placeholder::Str("author")) => {
// Unicode modifier should not be counted as character to allow a consistent padding
let unicode_modifier_width =
blame.author.chars().count() - UnicodeWidthStr::width(blame.author);
Some((Cow::from(blame.author), unicode_modifier_width))
}
Some(Placeholder::Str("commit")) => {
Some((delta::format_raw_line(blame.commit, config), 0))
}
Some(Placeholder::Str("author")) => Some(Cow::from(blame.author)),
Some(Placeholder::Str("commit")) => Some(delta::format_raw_line(blame.commit, config)),
None => None,
_ => unreachable!("Unexpected `git blame` input"),
};
if let Some(field) = field {
// Unicode modifier should not be counted as character to allow a consistent padding
let unicode_modifier_width =
field.as_ref().chars().count() - UnicodeWidthStr::width(field.as_ref());
if let Some((field, unicode_modifier_width)) = field {
s.push_str(&format::pad(
&field,
width + unicode_modifier_width,
Expand Down

0 comments on commit dc38ca9

Please sign in to comment.