loaders 0.0.0

A fully-featured, customisable progress bar and loading indicator library for Rust CLI and terminal applications
Documentation
use loaders::{ProgressBar, ProgressStyle};
use std::thread;
use std::time::Duration;

fn next_speed(seed: &mut u64) -> u64 {
    *seed = seed.wrapping_mul(6364136223846793005).wrapping_add(1);
    let span = 2 * 1024 * 1024 - 500 * 1024;
    500 * 1024 + ((*seed >> 32) % span)
}

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let total = 50 * 1024 * 1024;
    let style = ProgressStyle::with_template(
        "{prefix} [{bar:40}] {bytes}/{total_bytes} {bytes_per_sec} ETA {eta} {msg}",
    )?;
    let pb = ProgressBar::builder()
        .length(total)
        .style(style)
        .prefix("download")
        .message("output.bin")
        .build();

    let mut downloaded = 0u64;
    let mut seed = 42u64;
    while downloaded < total {
        let speed = next_speed(&mut seed);
        let chunk = (speed / 20).max(1).min(total - downloaded);
        downloaded += chunk;
        pb.inc(chunk);
        thread::sleep(Duration::from_millis(50));
    }
    pb.finish_with_message("Download complete! Saved to output.bin");
    Ok(())
}