From d9e81846d8c2b66a999b4c351ecf2d3c377018c7 Mon Sep 17 00:00:00 2001 From: o2sh Date: Sat, 7 Nov 2020 17:08:37 +0100 Subject: [PATCH] better var and fn naming --- src/onefetch/cli.rs | 6 +-- src/onefetch/cli_utils.rs | 4 +- src/onefetch/info.rs | 81 ++++++++++++++++++++------------------ src/onefetch/text_color.rs | 2 +- 4 files changed, 48 insertions(+), 45 deletions(-) diff --git a/src/onefetch/cli.rs b/src/onefetch/cli.rs index 8eb8e11af..2dfa3bba1 100644 --- a/src/onefetch/cli.rs +++ b/src/onefetch/cli.rs @@ -21,7 +21,7 @@ pub struct Cli { pub no_bold: bool, pub image: Option, pub image_backend: Option>, - pub image_colors: usize, + pub image_color_resolution: usize, pub no_merges: bool, pub no_color_palette: bool, pub number_of_authors: usize, @@ -258,7 +258,7 @@ impl Cli { return Err("Could not detect a supported image backend".into()); } - let image_colors = if let Some(value) = matches.value_of("color-resolution") { + let image_color_resolution = if let Some(value) = matches.value_of("color-resolution") { usize::from_str(value).unwrap() } else { 16 @@ -305,7 +305,7 @@ impl Cli { no_bold, image, image_backend, - image_colors, + image_color_resolution, no_merges, no_color_palette, number_of_authors, diff --git a/src/onefetch/cli_utils.rs b/src/onefetch/cli_utils.rs index b277a57da..53ba57785 100644 --- a/src/onefetch/cli_utils.rs +++ b/src/onefetch/cli_utils.rs @@ -37,7 +37,7 @@ impl Printer { .add_image( info_lines.map(|s| format!("{}{}", center_pad, s)).collect(), custom_image, - self.info.config.image_colors, + self.info.config.image_color_resolution, ) .chain_err(|| "Error while drawing image")?, ); @@ -45,7 +45,7 @@ impl Printer { let mut logo_lines = if let Some(custom_ascii) = &self.info.config.ascii_input { AsciiArt::new(custom_ascii, &colors, !self.info.config.no_bold) } else { - AsciiArt::new(self.get_ascii(), &self.info.colors, !self.info.config.no_bold) + AsciiArt::new(self.get_ascii(), &self.info.ascii_colors, !self.info.config.no_bold) }; loop { diff --git a/src/onefetch/info.rs b/src/onefetch/info.rs index 55ddfb2a4..e403cb161 100644 --- a/src/onefetch/info.rs +++ b/src/onefetch/info.rs @@ -29,8 +29,8 @@ pub struct Info { number_of_tags: usize, number_of_branches: usize, license: String, - pub colors: Vec, - pub color_set: TextColor, + pub ascii_colors: Vec, + pub text_colors: TextColor, pub config: Cli, } @@ -42,14 +42,14 @@ impl std::fmt::Display for Info { writeln!( f, "{} {} {}", - &self.bold(&self.git_username).color(self.color_set.title), - &self.bold("~").color(self.color_set.tilde), - &self.bold(&self.git_version).color(self.color_set.title) + &self.bold(&self.git_username).color(self.text_colors.title), + &self.bold("~").color(self.text_colors.tilde), + &self.bold(&self.git_version).color(self.text_colors.title) )?; let separator = "-".repeat(git_info_length); - writeln!(f, "{}", separator.color(self.color_set.underline))?; + writeln!(f, "{}", separator.color(self.text_colors.underline))?; } if !self.config.disabled_fields.project { @@ -61,8 +61,8 @@ impl std::fmt::Display for Info { f, "{}{} {}", project_str, - self.project_name.color(self.color_set.info), - branches_tags_str.color(self.color_set.info) + self.project_name.color(self.text_colors.info), + branches_tags_str.color(self.text_colors.info) )?; } @@ -71,7 +71,7 @@ impl std::fmt::Display for Info { f, "{}{}", &self.get_formatted_subtitle_label("HEAD"), - &self.current_commit.to_string().color(self.color_set.info), + &self.current_commit.to_string().color(self.text_colors.info), )?; } @@ -80,7 +80,7 @@ impl std::fmt::Display for Info { f, "{}{}", &self.get_formatted_subtitle_label("Pending"), - &self.pending.color(self.color_set.info), + &self.pending.color(self.text_colors.info), )?; } @@ -89,7 +89,7 @@ impl std::fmt::Display for Info { f, "{}{}", &self.get_formatted_subtitle_label("Version"), - &self.version.color(self.color_set.info), + &self.version.color(self.text_colors.info), )?; } @@ -98,7 +98,7 @@ impl std::fmt::Display for Info { f, "{}{}", &self.get_formatted_subtitle_label("Created"), - &self.creation_date.color(self.color_set.info), + &self.creation_date.color(self.text_colors.info), )?; } @@ -111,7 +111,7 @@ impl std::fmt::Display for Info { f, "{}{}", &self.get_formatted_subtitle_label(title), - languages_str.color(self.color_set.info) + languages_str.color(self.text_colors.info) )?; } @@ -120,7 +120,7 @@ impl std::fmt::Display for Info { f, "{}{}", &self.get_formatted_subtitle_label("Dependencies"), - &self.dependencies.color(self.color_set.info), + &self.dependencies.color(self.text_colors.info), )?; } @@ -133,7 +133,7 @@ impl std::fmt::Display for Info { f, "{}{}", &self.get_formatted_subtitle_label(title), - author_str.color(self.color_set.info), + author_str.color(self.text_colors.info), )?; } @@ -142,7 +142,7 @@ impl std::fmt::Display for Info { f, "{}{}", &self.get_formatted_subtitle_label("Last change"), - &self.last_change.color(self.color_set.info), + &self.last_change.color(self.text_colors.info), )?; } @@ -151,7 +151,7 @@ impl std::fmt::Display for Info { f, "{}{}", &self.get_formatted_subtitle_label("Repo"), - &self.repo_url.color(self.color_set.info), + &self.repo_url.color(self.text_colors.info), )?; } @@ -160,7 +160,7 @@ impl std::fmt::Display for Info { f, "{}{}", &self.get_formatted_subtitle_label("Commits"), - &self.commits.color(self.color_set.info), + &self.commits.color(self.text_colors.info), )?; } @@ -169,7 +169,7 @@ impl std::fmt::Display for Info { f, "{}{}", &self.get_formatted_subtitle_label("Lines of code"), - &self.lines_of_code.to_string().color(self.color_set.info), + &self.lines_of_code.to_string().color(self.text_colors.info), )?; } @@ -178,7 +178,7 @@ impl std::fmt::Display for Info { f, "{}{}", &self.get_formatted_subtitle_label("Size"), - &self.repo_size.color(self.color_set.info), + &self.repo_size.color(self.text_colors.info), )?; } @@ -187,7 +187,7 @@ impl std::fmt::Display for Info { f, "{}{}", &self.get_formatted_subtitle_label("License"), - &self.license.color(self.color_set.info), + &self.license.color(self.text_colors.info), )?; } @@ -233,13 +233,13 @@ impl Info { let project_license = Detector::new()?.get_project_license(workdir_str); let dominant_language = Language::get_dominant_language(&languages_stats); let dependencies = deps::DependencyDetector::new().get_dependencies(workdir_str)?; - let colors = Info::get_colors( + let ascii_colors = Info::get_ascii_colors( &config.ascii_language, &dominant_language, &config.ascii_colors, config.true_color, ); - let color_set = TextColor::get_text_color_set(&config.text_colors, &colors); + let text_colors = TextColor::get_text_colors(&config.text_colors, &ascii_colors); Ok(Info { git_version: git_v, @@ -261,8 +261,8 @@ impl Info { number_of_tags, number_of_branches, license: project_license?, - colors, - color_set, + ascii_colors, + text_colors, config, }) } @@ -555,7 +555,7 @@ impl Info { Ok(output) } - fn get_colors( + fn get_ascii_colors( ascii_language: &Language, dominant_language: &Language, ascii_colors: &[String], @@ -608,8 +608,11 @@ impl Info { } fn get_formatted_subtitle_label(&self, label: &str) -> ColoredString { - let formatted_label = - format!("{}{} ", label.color(self.color_set.subtitle), ":".color(self.color_set.colon)); + let formatted_label = format!( + "{}{} ", + label.color(self.text_colors.subtitle), + ":".color(self.text_colors.colon) + ); self.bold(&formatted_label) } @@ -632,19 +635,19 @@ impl Info { if i == 0 { author_field.push_str(&format!( "{}{} {} {}\n", - autor_contribution.to_string().color(self.color_set.info), - "%".color(self.color_set.info), - author_name.to_string().color(self.color_set.info), - author_nbr_commits.to_string().color(self.color_set.info), + autor_contribution.to_string().color(self.text_colors.info), + "%".color(self.text_colors.info), + author_name.to_string().color(self.text_colors.info), + author_nbr_commits.to_string().color(self.text_colors.info), )); } else { author_field.push_str(&format!( "{: TextColor { + pub fn get_text_colors(text_colors: &[String], default_colors: &[Color]) -> TextColor { let mut text_color_set = TextColor::new(default_colors[0]); if !text_colors.is_empty() { let custom_color = text_colors