Console progress bar for Rust

Overview

Terminal progress bar for Rust

Latest version License Docs Build Status Gitter

Console progress bar for Rust Inspired from pb, support and tested on MacOS, Linux and Windows

Screenshot

Documentation

Examples

  1. simple example
extern crate pbr;

use pbr::ProgressBar;
use std::thread;

fn main() {
    let count = 1000;
    let mut pb = ProgressBar::new(count);
    pb.format("╢▌▌░╟");
    for _ in 0..count {
        pb.inc();
        thread::sleep_ms(200);
    }
    pb.finish_print("done");
}
  1. MultiBar example. see full example here
extern crate pbr;

use std::thread;
use pbr::MultiBar;
use std::time::Duration;

fn main() {
    let mut mb = MultiBar::new();
    let count = 100;
    mb.println("Application header:");

    let mut p1 = mb.create_bar(count);
    let _ = thread::spawn(move || {
        for _ in 0..count {
            p1.inc();
            thread::sleep(Duration::from_millis(100));
        }
        // notify the multibar that this bar finished.
        p1.finish();
    });

    mb.println("add a separator between the two bars");

    let mut p2 = mb.create_bar(count * 2);
    let _ = thread::spawn(move || {
        for _ in 0..count * 2 {
            p2.inc();
            thread::sleep(Duration::from_millis(100));
        }
        // notify the multibar that this bar finished.
        p2.finish();
    });

    // start listen to all bars changes.
    // this is a blocking operation, until all bars will finish.
    // to ignore blocking, you can run it in a different thread.
    mb.listen();
}
  1. Broadcast writing (simple file copying)
#![feature(io)]
extern crate pbr;

use std::io::copy;
use std::io::prelude::*;
use std::fs::File;
use pbr::{ProgressBar, Units};

fn main() {
    let mut file = File::open("/usr/share/dict/words").unwrap();
    let n_bytes = file.metadata().unwrap().len() as usize;
    let mut pb = ProgressBar::new(n_bytes);
    pb.set_units(Units::Bytes);
    let mut handle = File::create("copy-words").unwrap().broadcast(&mut pb);
    copy(&mut file, &mut handle).unwrap();
    pb.finish_print("done");
}

License

MIT

Comments
  • Added message and tick fields in prefix

    Added message and tick fields in prefix

    • Added tick field to prefix:
      • Char field that looks like a loading symbol ; useful to show ProgressBar is still being updated even though no progress are made.
      • ** speed ** field looks odd when the bar is being updated with tick, so best option right now is to disable it (maybe later the speed calculation could take place in add instead of draw, so that only progress would result in speed calculation).
      • Calling pb.tick on a bar with 0 progress will result in a panic (division by zero), so be sure to have called pb.inc() at least once before using pb.tick()
    • Added message field to prefix:
      • message can be changed by calling pb.message("smthng")
      • message field will disappear when calling pb("").
      • message of same length should be used when frequently updating message, or it will result in a flickering of the ProgressBar"s bar field.

    Both those options require the user to call an init instruction of the lib to be displayed, so code using old versions of pb should display their ProgressBar as before without error.

    To use tick :

    // with default tick format: \|/-
    let pb = ProgressBar::new(...);
    pb.show_tick = true;
    ...
    pb.inc() 
    ...
    pb.tick()
    

    or

    // with custom tick format:
    let pb = ProgressBar::new(...);
    pb.tick_format(">^<v");
    ...
    

    To use message:

    let pb = ProgressBar::new();
    pb.message("msg");
    ...
    

    which means a ProgressBar::new() object will neither have a message field nor a tick field.

    A quick view of the new features (both are contained in test/lib.rs): a bar looking like npm install bar : https://asciinema.org/a/87m1dx8hgs43rmbos8kl52juk an example of command with wait time between progress : https://asciinema.org/a/5iqwcbai6rchk2sb3ropfvev9

    opened by althonos 8
  • No final redraw when max_refresh_rate is set

    No final redraw when max_refresh_rate is set

    Currently if you have a max refresh rate set it's possible that the bar is not rendered at 100% when it finishes. This is particularly noticable with progress bars that tick a lot but only have few steps (like 5 in total).

    opened by mitsuhiko 6
  • Fix Redox compilation

    Fix Redox compilation

    Redox now compiles with cfg(unix) and fully supports the functions used there. One test was disabled on Redox due to stty not being installed by default.

    opened by jackpot51 5
  • Add logging support for ProgressBar and MultiBar

    Add logging support for ProgressBar and MultiBar

    Hello :)

    I have added simple logging support to ProgressBar and MultiBar, hopefully in a way that doesn't cause issues for anyone who doesn't need it.

    Log messages are printed above the bar area and appear to move upward with each new log message, as you would expect.

    To allow ProgressBar to log messages when part of a MultiBar without significantly changing the way they are implemented, I have borrowed a trick from HTTP multipart/form-data and added an optional boundary string to Pipe.

    If that boundary string is included in a string sent across the Pipe to MultiBar, the string is split and the first section is treated as a log message, the second is the bar string. If no boundary is sent, it should operate exactly the same as it did before.

    I considered adding support for integration with the log crate, formatting, colors, and a way to present a virtual "log window" where the messages disappear at the top rather than continuing to scroll, but this seemed like a good start and those can be added later if necessary.

    All the existing tests pass, though some of the failing doc tests look like they were never intended to pass (missing variables).

    opened by steveatinfincia 5
  • Use the SI binary notation for formatted bytes

    Use the SI binary notation for formatted bytes

    Note: downstream branch was changed to si, this PR is not updated.

    This (fairly small) pull request modifies the byte notation slightly, to follow the international SI standard. It changes the KB notation to a better defined KiB notation, as we're working with a binary (1024 based) notation.

    SI standard: https://physics.nist.gov/cuu/Units/binary.html

    opened by timvisee 4
  • Type annotations required for rustc 1.18.0-nightly

    Type annotations required for rustc 1.18.0-nightly

    The latest release doesn't build with rustc 1.18.0-nightly (50c186419 2017-04-06)

    error[E0283]: type annotations required: cannot resolve std::string::String: std::convert::AsRef<_> --> …/pbr-0.3.1/src/pb.rs:348:64

        |
    348 |                         base = base + repeat!(self.bar_current.as_ref(), curr_count - 1) +
        |                                                                ^^^^^^
    
    opened by kornelski 4
  • Canno't specify good type of ProgressBar

    Canno't specify good type of ProgressBar

    Hi, I want to specify the type of a ProgressBar, created using create_bar from MultiBar, as a parameter of a function. Unfortunately, I can't because: module 'multi' is private.

    My specification is here:

    fn my_function(nb: ProgressBar<pbr::multi::Pipe>) {
    ...
    }
    

    How can I specify this type please?

    Thanks a lot!

    opened by k0pernicus 4
  • Allow dynamically adding and removing bars from MultiBar

    Allow dynamically adding and removing bars from MultiBar

    Thanks for this useful crate.

    I have one problem: My progress report keeps changing while I work on it. Specifically, I split some data into geometrically separated chunks - and this might recurse. I would love to add new progress bar and removes those that are done while my process runs. Is that a planned feature?

    opened by SirVer 3
  • weirdness when message has a newline character

    weirdness when message has a newline character

    I know this is kind of an edge case, but I noticed when I accidentally used a message string that had a newline character in it. pb doesn't deal with this case (either by stripping newlines or by drawing the progress bar differently), so it just spews out progress bar lines.

    opened by mcginty 3
  • Use floats for speed calculation

    Use floats for speed calculation

    When transferring in the ~100MB/s range (think copying a file on an SSD), you're down to the ~10 nanoseconds per byte range where the precision of storing a Duration containing the time per byte breaks down. Instead do the whole calculation in f64s representing seconds.

    opened by sfackler 3
  • feat: MultiBar is now thread-safe; Create new bars dynamically

    feat: MultiBar is now thread-safe; Create new bars dynamically

    Allows the creation of new progress bars while the MultiBar is already listening.

    By wrapping a MultiBar in an Arc, it can be safely shared and used across threads.

    Closes #35 Closes #87

    opened by mmstick 2
  • Cannot open include file: 'openssl/ssl.h': No such file or directory

    Cannot open include file: 'openssl/ssl.h': No such file or directory

     TARGET = Some("x86_64-pc-windows-msvc")
      OPT_LEVEL = Some("0")
      TARGET = Some("x86_64-pc-windows-msvc")
      HOST = Some("x86_64-pc-windows-msvc")
      TARGET = Some("x86_64-pc-windows-msvc")
      TARGET = Some("x86_64-pc-windows-msvc")
      HOST = Some("x86_64-pc-windows-msvc")
      CC_x86_64-pc-windows-msvc = None
      CC_x86_64_pc_windows_msvc = None
      HOST_CC = None
      CC = None
      TARGET = Some("x86_64-pc-windows-msvc")
      HOST = Some("x86_64-pc-windows-msvc")
      CFLAGS_x86_64-pc-windows-msvc = None
      CFLAGS_x86_64_pc_windows_msvc = None
      HOST_CFLAGS = None
      CFLAGS = None
      DEBUG = Some("true")
      running: "C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.34.31933\\bin\\HostX64\\x64\\cl.exe" "/nologo" "/MD" "/Z7" "/W4" "/FoC:\\Users\\SPT\\Desktop\\rust-grpc\\target\\debug\\build\\openssl-6f62ae9d80819d47\\out\\src/c_helpers.o" "/c" "src/c_helpers.c"
      c_helpers.c
      src/c_helpers.c(1): fatal error C1083: Cannot open include file: 'openssl/ssl.h': No such file or directory
      exit code: 2
    
      --- stderr
      thread 'main' panicked at '
    
      Internal error occurred: Command "C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.34.31933\\bin\\HostX64\\x64\\cl.exe" "/nologo" "/MD" "/Z7" "/W4" "/FoC:\\Users\\SPT\\Desktop\\rust-grpc\\target\\debug\\build\\openssl-6f62ae9d80819d47\\out\\src/c_helpers.o" "/c" "src/c_helpers.c" with args "cl.exe" did not execute successfully (status code exit code: 2).      
    
      ', C:\Users\SPT\.cargo\registry\src\github.com-1ecc6299db9ec823\gcc-0.3.55\src\lib.rs:1672:5
      note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
    

    I'm on Windows 11 and I have openssl (OpenSSL 3.0.7 1 Nov 2022 (Library: OpenSSL 3.0.7 1 Nov 2022) and all the environment variables are configured too

    opened by ash-hashtag 0
  • cargo audit vulnerability found on the time crate

    cargo audit vulnerability found on the time crate

    $ cargo audit
        Fetching advisory database from `https://github.com/RustSec/advisory-db.git`
        Loaded 457 security advisories (from /usr/local/cargo/advisory-db)
        Updating crates.io index
        Scanning Cargo.lock for vulnerabilities (46 crate dependencies)
    Crate:     time
    Version:   0.1.44
    Title:     Potential segfault in the time crate
    Date:      2020-11-18
    ID:        RUSTSEC-2020-0071
    URL:       https://rustsec.org/advisories/RUSTSEC-2020-0071
    Solution:  Upgrade to >=0.2.23
    Dependency tree:
    time 0.1.44
    └── pbr 1.0.4
        └── split-building-footprints 0.1.0 (my code)
    error: 1 vulnerability found!
    

    Hi. I've just started using pbr and cargo add pbr gave me version 1.0.4 but a cargo audit has found a vulnerability on the version of time used.

    opened by endafarrell 1
  • New release

    New release

    @a8m, could you please push a new release to crates.io? Would be good to be able to depend on https://github.com/a8m/pb/pull/100 and https://github.com/a8m/pb/pull/106.

    opened by LingMan 1
  • Progress Bars spam the terminal if the message is set too long

    Progress Bars spam the terminal if the message is set too long

    Given a single progress bar,

    If a message is set to a normal length it works as intended filename.mp4: 18.47 MB / 41.00 MB [===>----] 45.05 % 2.35 MB/s 10s

    However if the message becomes way too long, the terminal will spam with something such as

    [metadata] loooooooongfilename.mp4: 18.47 MB / 41.00 MB 45.05 % 2.35 MB/s 10s
    [metadata] loooooooongfilename.mp4: 18.47 MB / 41.00 MB 45.06 % 2.35 MB/s 10s
    [metadata] loooooooongfilename.mp4: 18.47 MB / 41.00 MB 45.07 % 2.35 MB/s 10s
    [metadata] loooooooongfilename.mp4: 18.47 MB / 41.00 MB 45.08 % 2.35 MB/s 10s
    [metadata] loooooooongfilename.mp4: 18.47 MB / 41.00 MB 45.09 % 2.35 MB/s 10s
    [metadata] loooooooongfilename.mp4: 18.47 MB / 41.00 MB 45.10 % 2.35 MB/s 10s
    

    The spam doesn't stop until the process is finished.

    opened by exKitsune 1
  • MultiBar does not honour custom handle on Windows

    MultiBar does not honour custom handle on Windows

    Hello,

    I am using a "/dev/null" like handle when my application is in quiet mode to hide the progress bar.

    On unix, tty::move_cursor_up returns a string which is output to the handle. On windows,tty::move_cursor_up print to the console and return an empty string whatever the handle is, making my trick to have a quiet mode totally failing.

    I do not know if the windows code could be fixed easily. Otherwise what about introducing a quiet mode ?

    opened by ririsoft 1
  • There is no way to align progress bars in MultiBar

    There is no way to align progress bars in MultiBar

    Here is what I see:

    7.85 GB / 13.96 GB ╢██████████████████████████░░░░░░░░░░░░░░░░░░░░░░░░░░░╟ 56.26 % 1.41 GB/s 4s
    7.82 GB / 7.82 GB ╢██████████████████████████████████████████████████████╟ 100.00 % 39.08 GB/s 
    3.37 GB / 21.79 GB ╢██████████░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░╟ 15.49 % 664.74 MB/s 28s
    

    Instead, it would be nice to see something like following:

    7.85 GB / 13.96 GB ╢██████████████████████████░░░░░░░░░░░░░░░░░░░░░░░░╟  56.26 %   1.41 GB/s  4s
    7.82 GB /  7.82 GB ╢██████████████████████████████████████████████████╟ 100.00 %  39.08 GB/s 
    3.37 GB / 21.79 GB ╢██████████░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░╟  15.49 % 664.74 MB/s 28s
    
    opened by kuznero 0
Releases(v1.0.3)
Owner
Ariel Mashraki
Ariel Mashraki
Rust Crate that allows to do interruptions in console. Will be implemented to functional terminal customization kit.

termpause Rust Crate that allows to do interruptions in console. Will be implemented to functional terminal customization kit. Usage Add this in your

Just Said 4 Sep 21, 2022
An ascii webcam in your console, written as a way of learning rust.

asciicam An ascii webcam in your console, written as a way of learning rust. asciicam picture of me holding a basketball usage only linux is supported

Vilhelm Bergsøe 3 Nov 15, 2022
A blazingly fast rust-based bionic reader for blazingly fast reading within a terminal console 🦀

This Rust-based CLI tool reads text and returns it back in bionic reading format for blazingly fast loading and even faster reading! Bionic reading is

Ismet Handzic 5 Aug 5, 2023
🌈 Brings back colour console to Win64 for Garry's Mod SRCDS

?? gmsv_concolormsg This module for Garry's Mod fixes x86-64 Windows 64-bit SRCDS not displaying colours. Why does it do that? Who knows! But it's eas

William 11 Oct 4, 2022
Simple console input macros with the goal of being implemented in the standard library.

Simple console input macros with the goal of being implemented in the standard library.

undersquire 2 Feb 10, 2022
Tldr - 📚 Collaborative cheatsheets for console commands

What is tldr-pages? The tldr-pages project is a collection of community-maintained help pages for command-line tools, that aims to be a simpler, more

tldr pages 42.4k Dec 29, 2022
A panic hook for wasm32-unknown-unknown that logs panics with console.error

console_error_panic_hook This crate lets you debug panics on wasm32-unknown-unknown by providing a panic hook that forwards panic messages to console.

Rust and WebAssembly 241 Jan 3, 2023
Wena is a micro-framework that provides an elegant starting point for your console application.

Wena was created by Nuno Maduro, and is a Rust Lang micro-framework that provides an elegant starting point for your console application. This project

null 251 Dec 11, 2022
scan markdown files and execute `console` blocks

exec-commands − scan markdown files and execute console blocks exec-commands is a utility to update command-line-tool examples embedded in markdown fi

Hajime Suzuki 3 Nov 27, 2022
Logging for text that should stay in the same place in a console.

console_static_text Crate for logging text that should stay in the same place in a console. This measures words to handle wrapping and has some consol

David Sherret 8 Dec 25, 2022
A command line progress reporting library for Rust

indicatif Documentation A Rust library for indicating progress in command line applications to users. This currently primarily provides progress bars

Armin Ronacher 3.2k Dec 30, 2022
Rust crate that allows you to display status & progress information in a terminal

status-line This crate allows you to display status & progress information in a terminal This crate handles the problem of displaying a small amount o

Piotr Kołaczkowski 20 Dec 27, 2022
Work-in-progress Rust application that converts C++ header-only libraries to single self-contained headers.

unosolo Work-in-progress Rust application that converts C++ header-only libraries to single self-contained headers. Disclaimer This is my first Rust p

Vittorio Romeo 26 Jul 9, 2021
A toy example showing how to run Rust code in Python for speed and progress.

PoC: Integrating Rust in Python A toy example showing how to run Rust code in Python for speed and progress. Requirements Python 3.6+ Rust 1.44+ Cargo

Emil Thorenfeldt 2 Feb 7, 2022
An experimental, work-in-progress PAM module for Tailscale

Experimental Tailscale PAM Module This is a very very experimental Tailscale PAM module that allows you to SSH using your Tailscale credentials. This

Tailscale 129 Nov 20, 2022
zman is a CLI year (time) progress that small, fast, and just one single binary.

zman zman is a CLI year (time) progress that small, fast, and just one single binary. Features Show year progress Show month, and week progress Show r

azzamsa 17 Dec 21, 2022
Work-in-progress software for managing the Azeron keypad on any operating system.

azeron-cli A small, unfinished CLI application intended to manage the Azeron Cyborg. The code is still in a very messy state and doesn't look very rus

cozyGalvinism 5 Nov 24, 2022
Work in progress NCBI's Common Tree alternative in the terminal

Lomanai Usage lomanai --species 'Mus musculus' --species 'Homo sapiens' #> Mammalia #> ++Rodentia #> | \-Mus musculus #> \+Primates #> \-Homo sapien

Jean Manguy 3 Dec 20, 2022
A work-in-progress static analyser.

Statan Statan is an early-stage static analyser for PHP and PXP projects. It is being developed in public and the journey is documented on my blog. Th

PXP 12 Jan 30, 2023