Make description an Option<String> and handle it in Display/Printable

i18n
Michal S 2 years ago committed by Michal
parent abef89abb4
commit ed58ef4d26

@ -24,7 +24,7 @@ pub struct PackageSearchResult {
pub groups: Option<Vec<String>>, pub groups: Option<Vec<String>>,
pub out_of_date: Option<u64>, pub out_of_date: Option<u64>,
pub installed: bool, pub installed: bool,
pub description: String, pub description: Option<String>,
} }
impl PackageSearchResult { impl PackageSearchResult {
@ -58,7 +58,13 @@ impl Display for PackageSearchResult {
} else { } else {
"".to_string() "".to_string()
}; };
let description = wrap_text(&self.description, 4).join("\n"); let description = wrap_text(
self.description
.clone()
.unwrap_or_else(|| "No description".to_string()),
4,
)
.join("\n");
format!("{repo}{name} {version}{groups}{out_of_date}{installed}\n {description}").fmt(f) format!("{repo}{name} {version}{groups}{out_of_date}{installed}\n {description}").fmt(f)
} }
@ -99,7 +105,13 @@ impl Printable for PackageSearchResult {
} }
.bold() .bold()
.cyan(); .cyan();
let description = wrap_text(&self.description, 4).join("\n"); let description = wrap_text(
self.description
.clone()
.unwrap_or_else(|| "No description".to_string()),
4,
)
.join("\n");
format!("{repo}{name} {version}{groups}{out_of_date}{installed}\n {description}") format!("{repo}{name} {version}{groups}{out_of_date}{installed}\n {description}")
} }
@ -137,7 +149,7 @@ pub async fn aur_search(
groups, groups,
out_of_date, out_of_date,
installed, installed,
description: description.unwrap_or_else(|| "No description".to_string()), description,
} }
}) })
.collect(); .collect();
@ -176,7 +188,7 @@ pub async fn repo_search(query: &str, options: Options) -> Vec<PackageSearchResu
groups, groups,
out_of_date, out_of_date,
installed, installed,
description: description.unwrap_or("No description").to_string(), description: Some(description.unwrap().to_string()),
}; };
results.push(result); results.push(result);

Loading…
Cancel
Save