summaryrefslogtreecommitdiffstats
path: root/src/handlers/blame.rs
diff options
context:
space:
mode:
authorThomas Otto <th1000s@posteo.net>2021-10-02 14:51:04 +0200
committerDan Davison <dandavison7@gmail.com>2021-10-18 10:41:12 -0400
commit3a03d4b5eede9a6c342a61941dd78c38c3559824 (patch)
tree9d9fb9d2a087b16f673decf22bf441e881b73a89 /src/handlers/blame.rs
parentcd50d301844991da65eaf613f753296217fb4cda (diff)
Convert Align and Placeholder into enums
Also move number and style logic out of `format_and_paint_line_numbers()` and into a separate `linenumbers_and_styles()` function.
Diffstat (limited to 'src/handlers/blame.rs')
-rw-r--r--src/handlers/blame.rs19
1 files changed, 12 insertions, 7 deletions
diff --git a/src/handlers/blame.rs b/src/handlers/blame.rs
index a82b8995..2c1b2222 100644
--- a/src/handlers/blame.rs
+++ b/src/handlers/blame.rs
@@ -5,7 +5,7 @@ use regex::Regex;
use crate::color;
use crate::config;
use crate::delta::{self, State, StateMachine};
-use crate::format;
+use crate::format::{self, Placeholder};
use crate::paint::BgShouldFill;
use crate::style::Style;
@@ -150,18 +150,23 @@ pub fn format_blame_metadata(
for placeholder in format_data {
s.push_str(placeholder.prefix.as_str());
- let alignment_spec = placeholder.alignment_spec.unwrap_or("<");
+ let alignment_spec = placeholder
+ .alignment_spec
+ .as_ref()
+ .unwrap_or(&format::Align::Left);
let width = placeholder.width.unwrap_or(15);
let pad = |s| format::pad(s, width, alignment_spec);
match placeholder.placeholder {
- Some("timestamp") => s.push_str(&pad(
- &chrono_humanize::HumanTime::from(blame.time).to_string()
+ Some(Placeholder::Str("timestamp")) => s.push_str(&pad(
+ &chrono_humanize::HumanTime::from(blame.time).to_string(),
)),
- Some("author") => s.push_str(&pad(blame.author)),
- Some("commit") => s.push_str(&pad(&delta::format_raw_line(blame.commit, config))),
+ Some(Placeholder::Str("author")) => s.push_str(&pad(blame.author)),
+ Some(Placeholder::Str("commit")) => {
+ s.push_str(&pad(&delta::format_raw_line(blame.commit, config)))
+ }
None => {}
- Some(_) => unreachable!(),
+ _ => unreachable!("Unexpected `git blame` input"),
}
suffix = placeholder.suffix.as_str();
}