pub fn color_green(s: &str) -> String { format!("\x1b[32m{}\x1b[0m", s) }
pub fn color_red(s: &str) -> String { format!("\x1b[31m{}\x1b[0m", s) }
pub fn color_yellow(s: &str) -> String { format!("\x1b[33m{}\x1b[0m", s) }
use indicatif::{ProgressBar, ProgressStyle};
pub fn join_pairs(pairs: &[(&str, &str)]) -> String {
pairs.iter().map(|(k, v)| format!("{k}: {v}")).collect::<Vec<_>>().join(", ")
}
pub fn clamp_timeout(secs: u64) -> u64 {
secs.clamp(5, 120)
}
pub fn create_progress_bar(len: u64) -> ProgressBar {
let pb = if len > 0 {
ProgressBar::new(len)
} else {
ProgressBar::new_spinner()
};
let style = if len > 0 {
ProgressStyle::with_template(
"Iskra · {bar:32.red/bright-red} {bytes:>8}/{total_bytes:<8} | {bytes_per_sec:>8} | ETA: {eta:>5}"
).unwrap()
.progress_chars("━╸ ")
} else {
ProgressStyle::with_template("Iskra · {spinner} Downloading...").unwrap()
};
pb.set_style(style);
pb.set_message("");
pb
}