8 个版本

0.1.4 2023 年 9 月 23 日
0.1.3 2023 年 5 月 24 日
0.1.2 2022 年 7 月 30 日
0.1.1 2022 年 3 月 23 日
0.0.2 2022 年 3 月 7 日

#165 in 图形 API

Download history 638/week @ 2024-03-13 892/week @ 2024-03-20 423/week @ 2024-03-27 630/week @ 2024-04-03 818/week @ 2024-04-10 577/week @ 2024-04-17 567/week @ 2024-04-24 742/week @ 2024-05-01 1078/week @ 2024-05-08 954/week @ 2024-05-15 487/week @ 2024-05-22 707/week @ 2024-05-29 840/week @ 2024-06-05 592/week @ 2024-06-12 437/week @ 2024-06-19 437/week @ 2024-06-26

2,459 每月下载量
用于 3 个 Crates (2 直接)

MIT 许可证

50KB
628

nutmeg - 一个无偏见的进度条库

https://github.com/sourcefrog/cargo-mutants

Tests docs.rs crates.io libs.rs Maturity: Beta

Nutmeg 在保持对终端进度指示符外观和内容的完全控制的同时绘制。

更多信息: https://docs.rs/nutmeg

许可证:MIT

示例

来自 examples/basic.rs

use std::io::Write; // to support write!()

// 1. Define a struct holding all the application state necessary to
// render the progress bar.
#[derive(Default)]
struct Model {
    i: usize,
    total: usize,
    last_file_name: String,
}

// 2. Define how to render the progress bar as a String.
impl nutmeg::Model for Model {
    fn render(&mut self, _width: usize) -> String {
        format!("{}/{}: {}", self.i, self.total, self.last_file_name)
    }
}

fn main() -> std::io::Result<()> {
    // 3. Create a View when you want to draw a progress bar.
    let mut view = nutmeg::View::new(Model::default(),
        nutmeg::Options::default());

    // 4. As the application runs, update the model via the view.
    let total_work = 100;
    view.update(|model| model.total = total_work);
    for i in 0..total_work {
        view.update(|model| {
            model.i += 1;
            model.last_file_name = format!("file{}.txt", i);
        });
        // 5. Interleave text output lines by writing to the view.
        if i % 10 == 3 {
            writeln!(view, "reached {}", i)?;
        }
        std::thread::sleep(std::time::Duration::from_millis(100));
    }

    // 5. The bar is automatically erased when dropped.
    Ok(())
}

asciicast

依赖项

~2–14MB
~139K SLoC