progress_bar

A Rust crate that allows you to display a progress bar in a terminal.

Latest version: 1.4.0 registry icon
Maintenance score
13
Safety score
100
Popularity score
71
Check your open source dependency risks. Get immediate insight about security, stability and licensing risks.
Security
  Vulnerabilities
Version Suggest Low Medium High Critical
1.4.0 0 0 0 0 0
1.3.0 0 0 0 0 0
1.2.1 0 0 0 0 0
1.2.0 0 0 0 0 0
1.1.1 0 0 0 0 0
1.1.0 0 0 0 0 0
1.0.6 0 0 0 0 0
1.0.5 0 0 0 0 0
1.0.4 0 0 0 0 0
1.0.3 0 0 0 0 0
1.0.2 0 0 0 0 0
1.0.1 0 0 0 0 0
1.0.0 0 0 0 0 0
0.1.3 0 0 0 0 0
0.1.2 0 0 0 0 0
0.1.1 0 0 0 0 0
0.1.0 0 0 0 0 0

Stability
Latest release:

1.4.0 - This version may not be safe as it has not been updated for a long time. Find out if your coding project uses this component and get notified of any reported security vulnerabilities with Meterian-X Open Source Security Platform

Licensing

Maintain your licence declarations and avoid unwanted licences to protect your IP the way you intended.

MIT   -   MIT License

Not a wildcard

Not proprietary

OSI Compliant



progress_bar

A simple and elegant crate for displaying progress bars in the terminal. It can estimate and display the remaining time, and includes logging utilities that integrate cleanly with your progress bar output.

⚠️ Note: This crate currently supports Unix-based systems only.

Features

  • Display a clean terminal progress bar
  • Show the current action to the left of the progress bar
  • Output log messages above the progress bar
  • Estimate and display remaining time
  • Integrate seamlessly with Rust’s log crate

Example

Using the global progress bar

The crate offers a global progress bar interface for convenience, so you don't have to manually manage ProgressBar instances.

use progress_bar::*;
use std::{thread::sleep, time::Duration};

// if you have 81 pages to load
init_progress_bar(81);
set_progress_bar_action("Loading", Color::Blue, Style::Bold);

for i in 0..81 {
    // load page
    sleep(Duration::from_millis(100));

    // log the result
    if i == 14 {
        print_progress_bar_info("Failed", "to load https://zefzef.zef", Color::Red, Style::Normal);
    } else if i == 41 {
        print_progress_bar_info("Success", "loading https://example.com", Color::Green, Style::Bold);
    }

    // increase the progress by 1
    inc_progress_bar();
}

finalize_progress_bar();

image displaying the output of the code above

Logging with the progress bar

Calls to print while a progress bar is active will mess with the output. To avoid this, you can use the print_progress_bar_info function to log messages while the progress bar is active.

Basic usage

use progress_bar::*;

init_progress_bar(100);

print_progress_bar_info("Loading", "website https://example.com", Color::Blue, Style::Bold);
print_progress_bar_info("Failed", "to load https://zefzef.zef", Color::Red, Style::Normal);

If you find this syntax too verbose, the crate allows you to use the progress bar as a logger directly.

Enable to logger feature to use this functionality.

# Add the logger feature in your Cargo.toml
progress_bar = { version = "*", features = ["logger"] }
use progress_bar::*;
use log::*;

init_logger().unwrap();
init_progress_bar(100);

info!("Loading website https://example.com");
warn!("Failed to load https://zefzef.zef");

Integrating with env_logger

It is also possible to set another logger to handle calls to logging functions, while

use progress_bar::*;
use env_logger::Env;
use log::*;

let inner = env_logger::Builder::from_env(Env::default()).build();
init_logger_with_inner(inner).unwrap();

info!("Loading website https://example.com");
warn!("Failed to load https://zefzef.zef");

License: MIT