#progress #progress-bar #terminal #ansi

nutmeg

An unopinionated progress bar library

8 releases

new 0.1.4 Sep 23, 2023
0.1.3 May 24, 2023
0.1.2 Jul 30, 2022
0.1.1 Mar 23, 2022
0.0.2 Mar 7, 2022

#7 in #progress-bar

Download history 108/week @ 2023-06-09 104/week @ 2023-06-16 64/week @ 2023-06-23 76/week @ 2023-06-30 117/week @ 2023-07-07 57/week @ 2023-07-14 135/week @ 2023-07-21 61/week @ 2023-07-28 46/week @ 2023-08-04 30/week @ 2023-08-11 48/week @ 2023-08-18 53/week @ 2023-08-25 37/week @ 2023-09-01 117/week @ 2023-09-08 102/week @ 2023-09-15 213/week @ 2023-09-22

486 downloads per month
Used in 2 crates

MIT license

50KB
628 lines

nutmeg - an unopinionated progress bar library

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

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

Nutmeg draws terminal progress indicators while giving the application complete control over their appearance and content.

For more information: https://docs.rs/nutmeg

License: MIT

Example

From 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

Dependencies

~0.5–11MB
~103K SLoC