use std::{time::Duration, fmt::Display, thread};
use kdam::{BarExt, term::Colorizer, Spinner, tqdm};
pub fn start(name: String, endpoint: usize) -> Progress {
Progress::new(name, endpoint)
}
pub struct Progress {
pb: kdam::Bar,
}
impl Progress {
pub fn new(name: String, endpoint: usize) -> Self {
let mut pb = tqdm!(
total = endpoint,
colour = "green",
mininterval = 0.1,
force_refresh = true,
desc = format!("[bold blue]RUNNING {}", name.to_uppercase()).as_str(),
bar_format = format!("{{animation}} {{elapsed}} {{perce}} {}", "{percentage:3.0}%".colorize("#EE6FF8")),
colour = "gradient(#5A56E0,#EE6FF8)",
spinner = Spinner::new(
&["▁▂▃", "▂▃▄", "▃▄▅", "▄▅▆", "▅▆▇", "▆▇█", "▇█▇", "█▇▆", "▇▆▅", "▆▅▄", "▅▄▃", "▄▃▂", "▃▂▁"],
30.0,
1.0,
)
);
pb.set_description(format!("[bold blue]RUNNING {}", name.to_uppercase()).as_str());
pb.write(name.colorize("bold white"));
Progress { pb: pb }
}
pub fn update(&mut self) {
self.pb.update(1);
}
pub fn completed(&mut self) {
self.pb.update(self.pb.total);
}
pub fn failed(&mut self,message: impl Display) {
self.pb.write(message.to_string().colorize("bold white") );
}
pub fn message(&mut self, message: String) {
self.pb.write(message);
}
pub fn progress(&mut self, message: impl Display) {
self.pb.write(message.to_string().colorize("bold cyan"));
self.pb.update(1);
}
}