Skip to content

Commit

Permalink
Refactor formatted label function to be a method of Info
Browse files Browse the repository at this point in the history
  • Loading branch information
ccmetz committed Oct 20, 2019
1 parent dccea3d commit ded5f48
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl fmt::Display for Info {
writeln!(
buffer,
"{}{}",
get_formatted_info_label("Project: ", color, self.bold_enabled),
self.get_formatted_info_label("Project: ", color),
self.project_name
)?;
}
Expand All @@ -74,7 +74,7 @@ impl fmt::Display for Info {
writeln!(
buffer,
"{}{}",
get_formatted_info_label("HEAD: ", color, self.bold_enabled),
self.get_formatted_info_label("HEAD: ", color),
self.current_commit
)?;
}
Expand All @@ -83,7 +83,7 @@ impl fmt::Display for Info {
writeln!(
buffer,
"{}{}",
get_formatted_info_label("Version: ", color, self.bold_enabled),
self.get_formatted_info_label("Version: ", color),
self.version
)?;
}
Expand All @@ -92,7 +92,7 @@ impl fmt::Display for Info {
writeln!(
buffer,
"{}{}",
get_formatted_info_label("Created: ", color, self.bold_enabled),
self.get_formatted_info_label("Created: ", color),
self.creation_date
)?;
}
Expand All @@ -113,15 +113,15 @@ impl fmt::Display for Info {
writeln!(
buffer,
"{}{}",
get_formatted_info_label(title, color, self.bold_enabled),
self.get_formatted_info_label(title, color),
s
)?;
} else {
let title = "Language: ";
writeln!(
buffer,
"{}{}",
get_formatted_info_label(title, color, self.bold_enabled),
self.get_formatted_info_label(title, color),
self.dominant_language
)?;
};
Expand All @@ -137,7 +137,7 @@ impl fmt::Display for Info {
writeln!(
buffer,
"{}{}% {} {}",
get_formatted_info_label(title, color, self.bold_enabled),
self.get_formatted_info_label(title, color),
self.authors[0].2,
self.authors[0].0,
self.authors[0].1
Expand All @@ -149,7 +149,7 @@ impl fmt::Display for Info {
writeln!(
buffer,
"{}{}% {} {}",
get_formatted_info_label(&title, color, self.bold_enabled),
self.get_formatted_info_label(&title, color),
author.2,
author.0,
author.1
Expand All @@ -161,7 +161,7 @@ impl fmt::Display for Info {
writeln!(
buffer,
"{}{}",
get_formatted_info_label("Last change: ", color, self.bold_enabled),
self.get_formatted_info_label("Last change: ", color),
self.last_change
)?;
}
Expand All @@ -170,7 +170,7 @@ impl fmt::Display for Info {
writeln!(
buffer,
"{}{}",
get_formatted_info_label("Repo: ", color, self.bold_enabled),
self.get_formatted_info_label("Repo: ", color),
self.repo
)?;
}
Expand All @@ -179,7 +179,7 @@ impl fmt::Display for Info {
writeln!(
buffer,
"{}{}",
get_formatted_info_label("Commits: ", color, self.bold_enabled),
self.get_formatted_info_label("Commits: ", color),
self.commits
)?;
}
Expand All @@ -188,7 +188,7 @@ impl fmt::Display for Info {
writeln!(
buffer,
"{}{}",
get_formatted_info_label("Lines of code: ", color, self.bold_enabled),
self.get_formatted_info_label("Lines of code: ", color),
self.number_of_lines
)?;
}
Expand All @@ -197,7 +197,7 @@ impl fmt::Display for Info {
writeln!(
buffer,
"{}{}",
get_formatted_info_label("Size: ", color, self.bold_enabled),
self.get_formatted_info_label("Size: ", color),
self.repo_size
)?;
}
Expand All @@ -206,7 +206,7 @@ impl fmt::Display for Info {
writeln!(
buffer,
"{}{}",
get_formatted_info_label("License: ", color, self.bold_enabled),
self.get_formatted_info_label("License: ", color),
self.license
)?;
}
Expand Down Expand Up @@ -340,15 +340,6 @@ fn true_len(line: &str) -> usize {
.len()
}

// Returns a formatted label with the desired color and boldness
fn get_formatted_info_label(label: &str, color: Color, bold: bool) -> ColoredString {
let mut formatted_label = label.color(color);
if bold {
formatted_label = formatted_label.bold();
}
formatted_label
}

struct CommitInfo {
commit: Oid,
refs: Vec<String>,
Expand Down Expand Up @@ -1142,6 +1133,15 @@ impl Info {
}
}

// Returns a formatted info label with the desired color and boldness
fn get_formatted_info_label(&self, label: &str, color: Color) -> ColoredString {
let mut formatted_label = label.color(color);
if self.bold_enabled {
formatted_label = formatted_label.bold();
}
formatted_label
}

fn colors(&self) -> Vec<Color> {
let language =
if let Language::Unknown = self.custom_logo {
Expand Down

0 comments on commit ded5f48

Please sign in to comment.