diff --git a/benches/repo.rs b/benches/repo.rs
index d1cc06960..05d552e31 100644
--- a/benches/repo.rs
+++ b/benches/repo.rs
@@ -1,6 +1,6 @@
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use gix::{open, ThreadSafeRepository};
-use onefetch::{cli::CliOptions, info::Info};
+use onefetch::{cli::CliOptions, info::build_info};
fn bench_repo_info(c: &mut Criterion) {
let name = "repo.sh".to_string();
@@ -13,7 +13,7 @@ fn bench_repo_info(c: &mut Criterion) {
c.bench_function("get repo information", |b| {
b.iter(|| {
- let result = black_box(Info::new(&config));
+ let result = black_box(build_info(&config));
assert!(result.is_ok());
})
});
diff --git a/src/info/author.rs b/src/info/author.rs
index e7843f2b9..c9bea46b3 100644
--- a/src/info/author.rs
+++ b/src/info/author.rs
@@ -1,10 +1,6 @@
use crate::{
cli::NumberSeparator,
- info::{
- format_number,
- utils::git::Commits,
- utils::info_field::{InfoField, InfoType},
- },
+ info::{format_number, utils::git::Commits, utils::info_field::InfoField},
};
use owo_colors::{DynColors, OwoColorize};
use serde::Serialize;
@@ -76,7 +72,7 @@ pub struct AuthorsInfo {
}
impl AuthorsInfo {
- pub fn new(info_color: DynColors, commits: &mut Commits) -> Self {
+ pub fn new(info_color: DynColors, commits: &Commits) -> Self {
let authors = commits.authors_to_display.clone();
Self {
authors,
@@ -119,10 +115,6 @@ impl InfoField for AuthorsInfo {
title
}
- fn r#type(&self) -> InfoType {
- InfoType::Authors
- }
-
fn should_color(&self) -> bool {
false
}
diff --git a/src/info/commits.rs b/src/info/commits.rs
index 80e0922eb..cfee20cca 100644
--- a/src/info/commits.rs
+++ b/src/info/commits.rs
@@ -2,11 +2,7 @@ use serde::Serialize;
use crate::{
cli::NumberSeparator,
- info::{
- format_number,
- utils::git::Commits,
- utils::info_field::{InfoField, InfoType},
- },
+ info::{format_number, utils::git::Commits, utils::info_field::InfoField},
};
#[derive(Serialize)]
@@ -41,10 +37,6 @@ impl InfoField for CommitsInfo {
fn title(&self) -> String {
"Commits".into()
}
-
- fn r#type(&self) -> InfoType {
- InfoType::Commits
- }
}
#[cfg(test)]
diff --git a/src/info/contributors.rs b/src/info/contributors.rs
index be9ed4415..e5b16429e 100644
--- a/src/info/contributors.rs
+++ b/src/info/contributors.rs
@@ -2,11 +2,7 @@ use serde::Serialize;
use crate::{
cli::NumberSeparator,
- info::{
- format_number,
- utils::git::Commits,
- utils::info_field::{InfoField, InfoType},
- },
+ info::{format_number, utils::git::Commits, utils::info_field::InfoField},
};
#[derive(Serialize)]
@@ -46,10 +42,6 @@ impl InfoField for ContributorsInfo {
fn title(&self) -> String {
"Contributors".into()
}
-
- fn r#type(&self) -> InfoType {
- InfoType::Contributors
- }
}
#[cfg(test)]
diff --git a/src/info/created.rs b/src/info/created.rs
index 95b5846f5..af95a5e26 100644
--- a/src/info/created.rs
+++ b/src/info/created.rs
@@ -1,8 +1,5 @@
use super::utils::format_time;
-use crate::info::{
- utils::git::Commits,
- utils::info_field::{InfoField, InfoType},
-};
+use crate::info::{utils::git::Commits, utils::info_field::InfoField};
use serde::Serialize;
#[derive(Serialize)]
@@ -31,10 +28,6 @@ impl InfoField for CreatedInfo {
fn title(&self) -> String {
"Created".into()
}
-
- fn r#type(&self) -> InfoType {
- InfoType::Created
- }
}
#[cfg(test)]
diff --git a/src/info/dependencies.rs b/src/info/dependencies.rs
index c1dfd510b..5fb6e40aa 100644
--- a/src/info/dependencies.rs
+++ b/src/info/dependencies.rs
@@ -1,9 +1,6 @@
use crate::{
cli::NumberSeparator,
- info::{
- format_number,
- utils::info_field::{InfoField, InfoType},
- },
+ info::{format_number, utils::info_field::InfoField},
};
use onefetch_manifest::Manifest;
use serde::Serialize;
@@ -40,10 +37,6 @@ impl InfoField for DependenciesInfo {
fn title(&self) -> String {
"Dependencies".into()
}
-
- fn r#type(&self) -> InfoType {
- InfoType::Dependencies
- }
}
#[cfg(test)]
diff --git a/src/info/description.rs b/src/info/description.rs
index c9673a0e5..540b62e4e 100644
--- a/src/info/description.rs
+++ b/src/info/description.rs
@@ -1,4 +1,4 @@
-use crate::info::utils::info_field::{InfoField, InfoType};
+use crate::info::utils::info_field::InfoField;
use onefetch_manifest::Manifest;
use serde::Serialize;
use std::fmt::Write;
@@ -50,10 +50,6 @@ impl InfoField for DescriptionInfo {
fn title(&self) -> String {
"Description".into()
}
-
- fn r#type(&self) -> InfoType {
- InfoType::Description
- }
}
#[cfg(test)]
diff --git a/src/info/head.rs b/src/info/head.rs
index 525f133a7..146d83867 100644
--- a/src/info/head.rs
+++ b/src/info/head.rs
@@ -1,4 +1,4 @@
-use crate::info::utils::info_field::{InfoField, InfoType};
+use crate::info::utils::info_field::InfoField;
use anyhow::{Context, Result};
use gix::{reference::Category, Reference, Repository};
use serde::Serialize;
@@ -72,10 +72,6 @@ impl InfoField for HeadInfo {
fn title(&self) -> String {
"HEAD".into()
}
-
- fn r#type(&self) -> InfoType {
- InfoType::Head
- }
}
#[cfg(test)]
diff --git a/src/info/langs/language.rs b/src/info/langs/language.rs
index 6d20414f7..9dcd3a44b 100644
--- a/src/info/langs/language.rs
+++ b/src/info/langs/language.rs
@@ -1,4 +1,4 @@
-use crate::info::utils::info_field::{InfoField, InfoType};
+use crate::info::utils::info_field::InfoField;
use owo_colors::OwoColorize;
use serde::Serialize;
use tokei;
@@ -158,9 +158,6 @@ impl InfoField for LanguagesInfo {
title
}
- fn r#type(&self) -> InfoType {
- InfoType::Languages
- }
fn should_color(&self) -> bool {
false
}
diff --git a/src/info/last_change.rs b/src/info/last_change.rs
index 8cd214687..4055d11b1 100644
--- a/src/info/last_change.rs
+++ b/src/info/last_change.rs
@@ -1,8 +1,5 @@
use super::utils::format_time;
-use crate::info::{
- utils::git::Commits,
- utils::info_field::{InfoField, InfoType},
-};
+use crate::info::{utils::git::Commits, utils::info_field::InfoField};
use serde::Serialize;
#[derive(Serialize)]
@@ -32,10 +29,6 @@ impl InfoField for LastChangeInfo {
fn title(&self) -> String {
"Last change".into()
}
-
- fn r#type(&self) -> InfoType {
- InfoType::LastChange
- }
}
#[cfg(test)]
diff --git a/src/info/license.rs b/src/info/license.rs
index 6095bf574..65dbc10bd 100644
--- a/src/info/license.rs
+++ b/src/info/license.rs
@@ -1,4 +1,4 @@
-use crate::info::utils::info_field::{InfoField, InfoType};
+use crate::info::utils::info_field::InfoField;
use anyhow::{bail, Result};
use askalono::{Store, TextData};
use onefetch_manifest::Manifest;
@@ -95,10 +95,6 @@ impl InfoField for LicenseInfo {
fn title(&self) -> String {
"License".into()
}
-
- fn r#type(&self) -> InfoType {
- InfoType::License
- }
}
#[cfg(test)]
diff --git a/src/info/loc.rs b/src/info/loc.rs
index e6bf11378..9b47af1b2 100644
--- a/src/info/loc.rs
+++ b/src/info/loc.rs
@@ -4,10 +4,7 @@ use serde::Serialize;
use crate::{
cli::NumberSeparator,
- info::{
- format_number,
- utils::info_field::{InfoField, InfoType},
- },
+ info::{format_number, utils::info_field::InfoField},
};
#[derive(Serialize)]
@@ -37,10 +34,6 @@ impl InfoField for LocInfo {
fn title(&self) -> String {
"Lines of code".into()
}
-
- fn r#type(&self) -> InfoType {
- InfoType::LinesOfCode
- }
}
#[cfg(test)]
diff --git a/src/info/mod.rs b/src/info/mod.rs
index d8f09f31e..9adba561e 100644
--- a/src/info/mod.rs
+++ b/src/info/mod.rs
@@ -14,6 +14,7 @@ use self::pending::PendingInfo;
use self::project::ProjectInfo;
use self::size::SizeInfo;
use self::title::Title;
+use self::url::get_repo_url;
use self::url::UrlInfo;
use self::utils::git::Commits;
use self::utils::info_field::{InfoField, InfoType};
@@ -22,6 +23,7 @@ use crate::cli::{is_truecolor_terminal, CliOptions, NumberSeparator, When};
use crate::ui::get_ascii_colors;
use crate::ui::text_colors::TextColors;
use anyhow::{Context, Result};
+use gix::Repository;
use num_format::ToFormattedString;
use onefetch_manifest::Manifest;
use owo_colors::{DynColors, OwoColorize, Style};
@@ -50,17 +52,13 @@ mod version;
#[derive(Serialize)]
#[serde(rename_all = "camelCase")]
pub struct Info {
- title: Title,
+ title: Option
,
info_fields: Vec>,
#[serde(skip_serializing)]
- disabled_fields: Vec,
- #[serde(skip_serializing)]
text_colors: TextColors,
#[serde(skip_serializing)]
no_color_palette: bool,
#[serde(skip_serializing)]
- no_title: bool,
- #[serde(skip_serializing)]
no_bold: bool,
#[serde(skip_serializing)]
pub dominant_language: Language,
@@ -68,24 +66,29 @@ pub struct Info {
pub ascii_colors: Vec,
}
+struct InfoBuilder {
+ title: Option,
+ info_fields: Vec>,
+ disabled_fields: Vec,
+ no_title: bool,
+}
+
impl std::fmt::Display for Info {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
//Title
- if !self.no_title {
- write!(f, "{}", self.title)?;
+ if let Some(title) = &self.title {
+ write!(f, "{}", title)?;
}
//Info lines
- for info_field in self
- .info_fields
- .iter()
- .filter(|x| x.has_value(&self.disabled_fields))
- {
- self.write_styled_info_line(
+ for info_field in self.info_fields.iter().filter(|x| !x.value().is_empty()) {
+ write_styled_info_line(
f,
&info_field.title(),
&info_field.value(),
info_field.should_color(),
+ self.no_bold,
+ &self.text_colors,
)?
}
@@ -109,170 +112,336 @@ impl std::fmt::Display for Info {
}
}
-impl Info {
- pub fn new(cli_options: &CliOptions) -> Result {
- let git_repo = gix::ThreadSafeRepository::discover_opts(
- &cli_options.input,
- gix::discover::upwards::Options {
- dot_git_only: true,
- ..Default::default()
- },
- Default::default(),
- )?
- .to_thread_local();
- let repo_path = get_work_dir(&git_repo)?;
-
- let loc_by_language_sorted_handle = std::thread::spawn({
- let ignored_directories = cli_options.info.exclude.clone();
- let language_types = cli_options.info.r#type.clone();
- let include_hidden = cli_options.info.include_hidden;
- let workdir = repo_path.clone();
- move || {
- langs::get_loc_by_language_sorted(
- &workdir,
- &ignored_directories,
- &language_types,
- include_hidden,
- )
- }
- });
-
- let loc_by_language = loc_by_language_sorted_handle
- .join()
- .ok()
- .context("BUG: panic in language statistics thread")??;
- let dominant_language = langs::get_main_language(&loc_by_language);
- let true_color = match cli_options.ascii.true_color {
- When::Always => true,
- When::Never => false,
- When::Auto => is_truecolor_terminal(),
- };
- let ascii_colors = get_ascii_colors(
- &cli_options.ascii.ascii_language,
- &dominant_language,
- &cli_options.ascii.ascii_colors,
- true_color,
- );
+pub fn build_info(cli_options: &CliOptions) -> Result {
+ let repo = gix::ThreadSafeRepository::discover_opts(
+ &cli_options.input,
+ gix::discover::upwards::Options {
+ dot_git_only: true,
+ ..Default::default()
+ },
+ Default::default(),
+ )?
+ .to_thread_local();
+ let repo_path = get_work_dir(&repo)?;
- let text_colors =
- TextColors::new(&cli_options.text_formatting.text_colors, ascii_colors[0]);
- let title = Title::new(
- &git_repo,
- text_colors.title,
- text_colors.tilde,
- text_colors.underline,
- !cli_options.text_formatting.no_bold,
- );
- let manifest = get_manifest(&repo_path)?;
- let description = DescriptionInfo::new(manifest.as_ref());
- let pending = PendingInfo::new(&git_repo)?;
- let repo_url = UrlInfo::new(&git_repo)?;
- let project = ProjectInfo::new(
- &git_repo,
- &repo_url.repo_url,
- manifest.as_ref(),
- cli_options.text_formatting.number_separator,
- )?;
- let head = HeadInfo::new(&git_repo)?;
- let version = VersionInfo::new(&git_repo, manifest.as_ref())?;
- let size = SizeInfo::new(&git_repo, cli_options.text_formatting.number_separator);
- let license = LicenseInfo::new(&repo_path, manifest.as_ref())?;
- let mut commits = Commits::new(
- git_repo,
- cli_options.info.no_merges,
- &cli_options.info.no_bots,
- cli_options.info.number_of_authors,
- cli_options.info.email,
- cli_options.text_formatting.number_separator,
- )?;
- let created = CreatedInfo::new(cli_options.text_formatting.iso_time, &commits);
- let languages = LanguagesInfo::new(
+ let loc_by_language_sorted_handle = std::thread::spawn({
+ let ignored_directories = cli_options.info.exclude.clone();
+ let language_types = cli_options.info.r#type.clone();
+ let include_hidden = cli_options.info.include_hidden;
+ let workdir = repo_path.clone();
+ move || {
+ langs::get_loc_by_language_sorted(
+ &workdir,
+ &ignored_directories,
+ &language_types,
+ include_hidden,
+ )
+ }
+ });
+
+ let loc_by_language = loc_by_language_sorted_handle
+ .join()
+ .ok()
+ .context("BUG: panic in language statistics thread")??;
+ let manifest = get_manifest(&repo_path)?;
+ let repo_url = get_repo_url(&repo)?;
+
+ let commits = Commits::new(
+ &repo,
+ cli_options.info.no_merges,
+ &cli_options.info.no_bots,
+ cli_options.info.number_of_authors,
+ cli_options.info.email,
+ cli_options.text_formatting.number_separator,
+ )?;
+ let true_color = match cli_options.ascii.true_color {
+ When::Always => true,
+ When::Never => false,
+ When::Auto => is_truecolor_terminal(),
+ };
+ let dominant_language = langs::get_main_language(&loc_by_language);
+ let ascii_colors = get_ascii_colors(
+ &cli_options.ascii.ascii_language,
+ &dominant_language,
+ &cli_options.ascii.ascii_colors,
+ true_color,
+ );
+
+ let text_colors = TextColors::new(&cli_options.text_formatting.text_colors, ascii_colors[0]);
+ let no_bold = cli_options.text_formatting.no_bold;
+ let number_separator = cli_options.text_formatting.number_separator;
+ let iso_time = cli_options.text_formatting.iso_time;
+ let number_of_languages = cli_options.info.number_of_languages;
+ let number_of_authors = cli_options.info.number_of_authors;
+
+ Ok(InfoBuilder::new(cli_options)?
+ .title(&repo, no_bold, &text_colors)
+ .project(&repo, &repo_url, &manifest, number_separator)?
+ .description(&manifest)
+ .head(&repo)?
+ .pending(&repo)?
+ .version(&repo, &manifest)?
+ .created(&commits, iso_time)
+ .languages(
&loc_by_language,
true_color,
- cli_options.info.number_of_languages,
- text_colors.info,
- );
- let dependencies = DependenciesInfo::new(
- manifest.as_ref(),
- cli_options.text_formatting.number_separator,
- );
- let authors = AuthorsInfo::new(text_colors.info, &mut commits);
- let last_change = LastChangeInfo::new(cli_options.text_formatting.iso_time, &commits);
- let contributors = ContributorsInfo::new(
- &commits,
- cli_options.info.number_of_authors,
- cli_options.text_formatting.number_separator,
- );
- let commits = CommitsInfo::new(&commits, cli_options.text_formatting.number_separator);
- let lines_of_code = LocInfo::new(
- &loc_by_language,
- cli_options.text_formatting.number_separator,
- );
+ number_of_languages,
+ &text_colors,
+ )
+ .dependencies(&manifest, number_separator)
+ .authors(&commits, &text_colors)
+ .last_change(&commits, iso_time)
+ .contributors(&commits, number_of_authors, number_separator)
+ .url(&repo_url)
+ .commits(&commits, number_separator)
+ .loc(&loc_by_language, number_separator)
+ .size(&repo, number_separator)
+ .license(&repo_path, &manifest)?
+ .build(cli_options, text_colors, dominant_language, ascii_colors))
+}
- let info_fields: Vec> = vec![
- Box::new(project),
- Box::new(description),
- Box::new(head),
- Box::new(pending),
- Box::new(version),
- Box::new(created),
- Box::new(languages),
- Box::new(dependencies),
- Box::new(authors),
- Box::new(last_change),
- Box::new(contributors),
- Box::new(repo_url),
- Box::new(commits),
- Box::new(lines_of_code),
- Box::new(size),
- Box::new(license),
- ];
+impl InfoBuilder {
+ fn new(cli_options: &CliOptions) -> Result {
Ok(Self {
- title,
- info_fields,
+ title: None,
+ info_fields: Vec::new(),
disabled_fields: cli_options.info.disabled_fields.clone(),
+ no_title: cli_options.info.no_title,
+ })
+ }
+
+ fn title(mut self, repo: &Repository, no_bold: bool, text_colors: &TextColors) -> Self {
+ if !self.no_title {
+ let title = Title::new(
+ repo,
+ text_colors.title,
+ text_colors.tilde,
+ text_colors.underline,
+ !no_bold,
+ );
+ self.title = Some(title);
+ }
+ self
+ }
+
+ fn description(mut self, manifest: &Option) -> Self {
+ if !self.disabled_fields.contains(&InfoType::Description) {
+ let description = DescriptionInfo::new(manifest.as_ref());
+ self.info_fields.push(Box::new(description));
+ }
+ self
+ }
+
+ fn pending(mut self, repo: &Repository) -> Result {
+ if !self.disabled_fields.contains(&InfoType::Pending) {
+ let pending = PendingInfo::new(repo)?;
+ self.info_fields.push(Box::new(pending));
+ }
+ Ok(self)
+ }
+
+ fn url(mut self, repo_url: &str) -> Self {
+ if !self.disabled_fields.contains(&InfoType::URL) {
+ let repo_url = UrlInfo::new(repo_url);
+ self.info_fields.push(Box::new(repo_url));
+ }
+ self
+ }
+
+ fn project(
+ mut self,
+ repo: &Repository,
+ repo_url: &str,
+ manifest: &Option,
+ number_separator: NumberSeparator,
+ ) -> Result {
+ if !self.disabled_fields.contains(&InfoType::Project) {
+ let project = ProjectInfo::new(repo, repo_url, manifest.as_ref(), number_separator)?;
+ self.info_fields.push(Box::new(project));
+ }
+ Ok(self)
+ }
+
+ fn head(mut self, repo: &Repository) -> Result {
+ if !self.disabled_fields.contains(&InfoType::Head) {
+ let head = HeadInfo::new(repo)?;
+ self.info_fields.push(Box::new(head));
+ }
+ Ok(self)
+ }
+
+ fn version(mut self, repo: &Repository, manifest: &Option) -> Result {
+ if !self.disabled_fields.contains(&InfoType::Version) {
+ let version = VersionInfo::new(repo, manifest.as_ref())?;
+ self.info_fields.push(Box::new(version));
+ }
+ Ok(self)
+ }
+
+ fn size(mut self, repo: &Repository, number_separator: NumberSeparator) -> Self {
+ if !self.disabled_fields.contains(&InfoType::Size) {
+ let size = SizeInfo::new(repo, number_separator);
+ self.info_fields.push(Box::new(size));
+ }
+ self
+ }
+
+ fn license(mut self, repo_path: &Path, manifest: &Option) -> Result {
+ if !self.disabled_fields.contains(&InfoType::License) {
+ let license = LicenseInfo::new(repo_path, manifest.as_ref())?;
+ self.info_fields.push(Box::new(license));
+ }
+ Ok(self)
+ }
+
+ fn created(mut self, commits: &Commits, iso_time: bool) -> Self {
+ if !self.disabled_fields.contains(&InfoType::Created) {
+ let created = CreatedInfo::new(iso_time, commits);
+ self.info_fields.push(Box::new(created));
+ }
+ self
+ }
+
+ fn languages(
+ mut self,
+ loc_by_language: &[(Language, usize)],
+ true_color: bool,
+ number_of_languages: usize,
+ text_colors: &TextColors,
+ ) -> Self {
+ if !self.disabled_fields.contains(&InfoType::Languages) {
+ let languages = LanguagesInfo::new(
+ loc_by_language,
+ true_color,
+ number_of_languages,
+ text_colors.info,
+ );
+ self.info_fields.push(Box::new(languages));
+ }
+ self
+ }
+
+ fn dependencies(
+ mut self,
+ manifest: &Option,
+ number_separator: NumberSeparator,
+ ) -> Self {
+ if !self.disabled_fields.contains(&InfoType::Dependencies) {
+ let dependencies = DependenciesInfo::new(manifest.as_ref(), number_separator);
+ self.info_fields.push(Box::new(dependencies));
+ }
+ self
+ }
+
+ fn authors(mut self, commits: &Commits, text_colors: &TextColors) -> Self {
+ if !self.disabled_fields.contains(&InfoType::Authors) {
+ let authors = AuthorsInfo::new(text_colors.info, commits);
+ self.info_fields.push(Box::new(authors));
+ }
+ self
+ }
+
+ fn last_change(mut self, commits: &Commits, iso_time: bool) -> Self {
+ if !self.disabled_fields.contains(&InfoType::LastChange) {
+ let last_change = LastChangeInfo::new(iso_time, commits);
+ self.info_fields.push(Box::new(last_change));
+ }
+ self
+ }
+
+ fn contributors(
+ mut self,
+ commits: &Commits,
+ number_of_authors: usize,
+ number_separator: NumberSeparator,
+ ) -> Self {
+ if !self.disabled_fields.contains(&InfoType::Contributors) {
+ let contributors = ContributorsInfo::new(commits, number_of_authors, number_separator);
+ self.info_fields.push(Box::new(contributors));
+ }
+ self
+ }
+
+ fn commits(mut self, commits: &Commits, number_separator: NumberSeparator) -> Self {
+ if !self.disabled_fields.contains(&InfoType::Commits) {
+ let commits = CommitsInfo::new(commits, number_separator);
+ self.info_fields.push(Box::new(commits));
+ }
+ self
+ }
+
+ fn loc(
+ mut self,
+ loc_by_language: &[(Language, usize)],
+ number_separator: NumberSeparator,
+ ) -> Self {
+ if !self.disabled_fields.contains(&InfoType::LinesOfCode) {
+ let lines_of_code = LocInfo::new(loc_by_language, number_separator);
+ self.info_fields.push(Box::new(lines_of_code));
+ }
+ self
+ }
+
+ fn build(
+ self,
+ cli_options: &CliOptions,
+ text_colors: TextColors,
+ dominant_language: Language,
+ ascii_colors: Vec,
+ ) -> Info {
+ Info {
+ title: self.title,
+ info_fields: self.info_fields,
text_colors,
dominant_language,
ascii_colors,
no_color_palette: cli_options.visuals.no_color_palette,
- no_title: cli_options.info.no_title,
no_bold: cli_options.text_formatting.no_bold,
- })
+ }
}
+}
- fn write_styled_info_line(
- &self,
- f: &mut std::fmt::Formatter,
- subtitle: &str,
- info: &str,
- should_color_info: bool,
- ) -> std::fmt::Result {
- writeln!(
- f,
- "{} {}",
- &self.style_subtitle(subtitle),
- &self.style_info(info, should_color_info)
- )
- }
+fn write_styled_info_line(
+ f: &mut std::fmt::Formatter,
+ subtitle: &str,
+ info: &str,
+ should_color_info: bool,
+ no_bold: bool,
+ text_colors: &TextColors,
+) -> std::fmt::Result {
+ writeln!(
+ f,
+ "{} {}",
+ style_subtitle(subtitle, text_colors, no_bold),
+ style_info(info, text_colors, should_color_info)
+ )
+}
- fn style_info(&self, info: &str, with_color: bool) -> String {
- if with_color {
- let info_style = get_style(false, self.text_colors.info);
- format!("{}", info.style(info_style))
- } else {
- info.into()
- }
+fn style_info(info: &str, text_colors: &TextColors, with_color: bool) -> String {
+ if with_color {
+ let info_style = get_style(false, text_colors.info);
+ format!("{}", info.style(info_style))
+ } else {
+ info.into()
}
+}
- fn style_subtitle(&self, subtitle: &str) -> String {
- let subtitle_style = get_style(!self.no_bold, self.text_colors.subtitle);
- let colon_style = get_style(!self.no_bold, self.text_colors.colon);
- format!(
- "{}{}",
- subtitle.style(subtitle_style),
- ":".style(colon_style)
- )
+fn style_subtitle(subtitle: &str, text_colors: &TextColors, no_bold: bool) -> String {
+ let subtitle_style = get_style(!no_bold, text_colors.subtitle);
+ let colon_style = get_style(!no_bold, text_colors.colon);
+ format!(
+ "{}{}",
+ subtitle.style(subtitle_style),
+ ":".style(colon_style)
+ )
+}
+
+fn get_style(is_bold: bool, color: DynColors) -> Style {
+ let mut style = Style::new().color(color);
+ if is_bold {
+ style = style.bold();
}
+ style
}
fn get_manifest(repo_path: &Path) -> Result