A simple console progress bar. Progress bar writing now runs on another thread.
Menlo, Fira Mono, Source Code Pro or SF Mono are recommended for optimal visual effects.
For Consolas or Andale Mono fonts, use ProgressBarStyle.ASCII (see below) because the box-drawing glyphs are not aligned properly in these fonts.
Maven:
<dependency>
<groupId>me.tongfei</groupId>
<artifactId>progressbar</artifactId>
<version>0.5.5</version>
</dependency>Usage:
ProgressBar pb = new ProgressBar("Test", 100); // name, initial max
// Use ProgressBar("Test", 100, ProgressBarStyle.ASCII) if you want ASCII output style
pb.start(); // the progress bar starts timing
// Or you could combine these two lines like this:
// ProgressBar pb = new ProgressBar("Test", 100).start();
some loop {
...
pb.step(); // step by 1
pb.stepBy(n); // step by n
...
pb.stepTo(n); // step directly to n
...
pb.maxHint(n);
// reset the max of this progress bar as n. This may be useful when the program
// gets new information about the current progress.
// Can set n to be less than zero: this means that this progress bar would become
// indefinite: the max would be unknown.
...
pb.setExtraMessage("Reading..."); // Set extra message to display at the end of the bar
}
pb.stop() // stops the progress bar0.5.5: Fixed the problem of the progress bar being stuck if it finishes too fast. Fixed the problem ofStringIndexOutOfBoundsExceptionerror when the console width is too small. Thanks @bwittwer, @rholdberh and @bubyakin !0.5.4: Added indefinite progress bar support.0.5.3: Type of max/current of a progress bar is changed frominttolong. Thanks @vitobellini !0.5.2: Methods now returnsthis. This simplifies the initialization: Now you can dopb = new ProgressBar(...).start(). Extra messages that are too long are trimmed properly. Thanks @mattcg !0.5.1: Fixed the refresh problem when progress ended. Added style (Unicode block characters / pure ASCII) support.0.5.0: Separated the progress bar thread from the main thread for better performance. Fixed the character offset issue. Thanks @rualpe !0.4.3: Changed the symbols to box-drawing characters; more fine-grained display. Thanks @hrj !0.4.2: Default output stream is changed toSystem.err; can be customized in constructor. Thanks @AluisioASG !0.4.1: Added astepTomethod toProgressBars. Thanks @svenmauer !0.4.0: Migrated from Scala to Java: less dependencies.

