Skip to content

Commit 8a103b0

Browse files
authored
refactor(show): use key_style fn to render key style (#580)
1 parent 1756f15 commit 8a103b0

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/subcommand/show.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
use std::{io::stdout, path::PathBuf};
1+
use std::{borrow::Cow, io::stdout, path::PathBuf};
22

33
use clap::Args;
44
use clap_complete::ArgValueCompleter;
5-
use dialoguer::console::style;
5+
use dialoguer::console::{StyledObject, style};
66
use oma_console::indicatif::HumanBytes;
77
use oma_pm::{
88
apt::{AptConfig, OmaApt, OmaAptArgs},
@@ -169,9 +169,9 @@ fn display_records(stdout: &mut std::io::Stdout, pkg: &OmaPackage, apt: &OmaApt)
169169
}
170170

171171
let i = if *i == RecordField::Size {
172-
style("Download-Size:").bold().to_string()
172+
key_style(Cow::Borrowed("Download-Size:"))
173173
} else {
174-
style(format!("{i}:")).bold().to_string()
174+
key_style(format!("{i}:").into())
175175
};
176176

177177
writeln!(stdout, "{i} {v}").ok();
@@ -182,7 +182,7 @@ fn display_records(stdout: &mut std::io::Stdout, pkg: &OmaPackage, apt: &OmaApt)
182182
.map(AptSource::from)
183183
.collect::<Vec<_>>();
184184

185-
write!(stdout, "{}", style("APT-Sources:").bold()).ok();
185+
write!(stdout, "{}", key_style("APT-Sources:".into())).ok();
186186
let apt_sources_without_dpkg = apt_sources
187187
.iter()
188188
.filter(|x| x.index_type.as_deref() != Some("Debian dpkg status file"))
@@ -204,11 +204,16 @@ fn display_records(stdout: &mut std::io::Stdout, pkg: &OmaPackage, apt: &OmaApt)
204204
}
205205

206206
if version.is_installed() {
207-
write!(stdout, "{}", style("APT-Manual-Installed: ").bold()).ok();
207+
write!(stdout, "{}", key_style("APT-Manual-Installed: ".into())).ok();
208208
if version.parent().is_auto_installed() {
209209
writeln!(stdout, "no").ok();
210210
} else {
211211
writeln!(stdout, "yes").ok();
212212
}
213213
}
214214
}
215+
216+
#[inline]
217+
fn key_style(key: Cow<str>) -> StyledObject<Cow<str>> {
218+
style(key).bold()
219+
}

0 commit comments

Comments
 (0)