#progress-bar #bars #terminal #percentage #sleep #thread #p-bar

pbars

一个用于快速轻松创建进度条的crate

3个版本

0.1.2 2022年2月4日
0.1.1 2022年2月4日
0.1.0 2022年2月4日

6 in #bars

MIT许可证

24KB
254 代码行

pbars

一个用于终端进度条的Rust crate。
image

示例

use pbars::{PBar, BarType};
use std::thread::sleep;
use std::time::Duration;

fn main() {
    // using crossterm, this will create a pbar at 0,0
    // without crossterm, this is the only way to create a bar
    let mut pbar = PBar::new(BarType::Bar, true, true, 20);

    for x in 0..1000 {
        // get the percentage complete as a decimal
        let percentage_decimal = x as f32 / 1000.0;
        // scale the percentage from 0..1 to 0..100 and convert to a u8
        let percent = (percentage_decimal * 100.0) as u8;
        // update the pbar
        pbar.update(percent);
        // draw the pbar
        pbar.draw();
        // delay for 10ms, making this run in 10 seconds
        sleep(Duration::from_millis(10));
    }
}

依赖项

~4MB
~36K SLoC