mirror of
https://github.com/marcoallegretti/karapace.git
synced 2026-03-26 21:43:09 +00:00
fix(cli): avoid panics in progress styling
This commit is contained in:
parent
064981f716
commit
06b8889d27
1 changed files with 10 additions and 7 deletions
|
|
@ -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}"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue