fix(cli): avoid panics in progress styling

This commit is contained in:
Marco Allegretti 2026-02-25 12:28:28 +01:00
parent 064981f716
commit 06b8889d27

View file

@ -40,23 +40,26 @@ pub fn json_pretty(value: &impl serde::Serialize) -> Result<String, String> {
pub fn spinner(msg: &str) -> ProgressBar { pub fn spinner(msg: &str) -> ProgressBar {
let pb = ProgressBar::new_spinner(); let pb = ProgressBar::new_spinner();
pb.set_style( let style = ProgressStyle::with_template("{spinner:.cyan} {msg}")
ProgressStyle::with_template("{spinner:.cyan} {msg}") .unwrap_or_else(|_| ProgressStyle::default_spinner())
.expect("valid template") .tick_strings(&["", "", "", "", "", "", "", "", "", ""]);
.tick_strings(&["", "", "", "", "", "", "", "", "", ""]), pb.set_style(style);
);
pb.set_message(msg.to_owned()); pb.set_message(msg.to_owned());
pb.enable_steady_tick(Duration::from_millis(80)); pb.enable_steady_tick(Duration::from_millis(80));
pb pb
} }
pub fn spin_ok(pb: &ProgressBar, msg: &str) { pub fn spin_ok(pb: &ProgressBar, msg: &str) {
pb.set_style(ProgressStyle::with_template("{msg}").expect("valid template")); if let Ok(style) = ProgressStyle::with_template("{msg}") {
pb.set_style(style);
}
pb.finish_with_message(format!("{msg}")); pb.finish_with_message(format!("{msg}"));
} }
pub fn spin_fail(pb: &ProgressBar, msg: &str) { pub fn spin_fail(pb: &ProgressBar, msg: &str) {
pb.set_style(ProgressStyle::with_template("{msg}").expect("valid template")); if let Ok(style) = ProgressStyle::with_template("{msg}") {
pb.set_style(style);
}
pb.finish_with_message(format!("{msg}")); pb.finish_with_message(format!("{msg}"));
} }