iskra 0.4.0

A safe, modern, Rust-native data transfer tool.
Documentation

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};

/// Join header or query pairs into a display string (for debugging/logging).
pub fn join_pairs(pairs: &[(&str, &str)]) -> String {
    pairs.iter().map(|(k, v)| format!("{k}: {v}")).collect::<Vec<_>>().join(", ")
}
/// Clamp a timeout value to a reasonable range (5-120 seconds).
pub fn clamp_timeout(secs: u64) -> u64 {
    secs.clamp(5, 120)
}
/// Create and configure a progress bar for downloads.
/// If length is 0, show a spinner; otherwise, show a bar with bytes and ETA.
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
}