use std::time::Duration;
use console::{Emoji, style};
use indicatif::{HumanDuration, MultiProgress, ProgressBar, ProgressStyle};
pub static LOOKING_GLASS: Emoji<'_, '_> = Emoji("🔍 ", "");
pub static PACKAGE: Emoji<'_, '_> = Emoji("📦 ", "");
pub static DISK: Emoji<'_, '_> = Emoji("💾 ", "");
pub static GEAR: Emoji<'_, '_> = Emoji("⚙️ ", "");
pub static SPARKLE: Emoji<'_, '_> = Emoji("✨ ", "");
pub static TRUCK: Emoji<'_, '_> = Emoji("🚚 ", "");
pub static LINK: Emoji<'_, '_> = Emoji("🔗 ", "");
pub static DOCUMENT: Emoji<'_, '_> = Emoji("📄 ", "");
pub static PICTURE: Emoji<'_, '_> = Emoji("🖼️ ", "");
pub static CUBE: Emoji<'_, '_> = Emoji("📐 ", "");
pub fn print_step(current: usize, total: usize, emoji: Emoji, msg: &str) {
println!(
"{} {}{}",
style(format!("[{current}/{total}]")).bold().dim(),
emoji,
msg
);
}
pub fn print_done(elapsed: Duration) {
println!("{} Done in {}", SPARKLE, HumanDuration(elapsed));
}
#[must_use]
pub fn spinner_style() -> ProgressStyle {
ProgressStyle::with_template("{prefix:.bold.dim} {spinner} {wide_msg}")
.expect("valid template")
.tick_chars("⠁⠂⠄⡀⢀⠠⠐⠈ ")
}
#[must_use]
pub fn bar_style() -> ProgressStyle {
ProgressStyle::default_bar()
.template("{msg} [{bar:40.cyan/blue}] {pos}/{len}")
.expect("valid template")
}
#[must_use]
pub fn bar_style_with_percent() -> ProgressStyle {
ProgressStyle::default_bar()
.template("{msg} [{bar:40.cyan/blue}] {percent}% ({pos}/{len})")
.expect("valid template")
}
#[must_use]
pub fn multi_progress() -> MultiProgress {
MultiProgress::new()
}
#[must_use]
pub fn add_spinner(mp: &MultiProgress, prefix: &str, msg: &str) -> ProgressBar {
let pb = mp.add(ProgressBar::new_spinner());
pb.set_style(spinner_style());
pb.set_prefix(prefix.to_string());
pb.set_message(msg.to_string());
pb.enable_steady_tick(Duration::from_millis(100));
pb
}
#[must_use]
pub fn add_bar(mp: &MultiProgress, total: u64, msg: &str) -> ProgressBar {
let pb = mp.add(ProgressBar::new(total));
pb.set_style(bar_style());
pb.set_message(msg.to_string());
pb
}
#[must_use]
pub fn simple_spinner(msg: &str) -> ProgressBar {
let pb = ProgressBar::new_spinner();
pb.set_style(
ProgressStyle::default_spinner()
.template("{spinner:.cyan} {msg}")
.expect("valid template"),
);
pb.set_message(msg.to_string());
pb.enable_steady_tick(Duration::from_millis(100));
pb
}
#[must_use]
pub fn simple_bar(total: u64, msg: &str) -> ProgressBar {
let pb = ProgressBar::new(total);
pb.set_style(bar_style());
pb.set_message(msg.to_string());
pb
}