status_tracker/
lib.rs

1use std::io::{self, Write};
2
3pub fn status_tracker(current: usize, start: usize, end: usize, width: usize) {
4    let total = if start >= end { 1 } else { end - start };
5    let progress = if current < start { 0 } else { current - start };
6
7    let fraction = (progress as f64 / total as f64).min(1.0);
8    let percentage = (fraction * 100.0) as u32;
9
10    let filled_len = (fraction * width as f64) as usize;
11    let empty_len = width.saturating_sub(filled_len);
12
13    let filled = if filled_len > 0 {
14        format!("{}>", "=".repeat(filled_len - 1))
15    } else {
16        "".to_string()
17    };
18
19    let empty = " ".repeat(empty_len);
20
21    print!("\r\x1b[2K[{}{}] -> {}%", filled, empty, percentage);
22    io::stdout().flush().unwrap();
23}