progressbar
JVM的控制台进度栏,其开销很少。
建议使用Menlo,Fira Mono,Source Code Pro,Iosevka,Jetbrains Mono或SF Mono,以获得最佳的视觉效果。
对于Consolas或Andale Mono字体,请使用progressbar Style.ASCII ,因为在这些字体中不正确对齐盒子的字形。
文档
- 文档
- Javadoc
安装
马文:
progressbar</artifactId>
<version>0.10.0</version>
</dependency>\”>
< dependency > < groupId >me.tongfei</ groupId > < artifactId > progressbar </ artifactId > < version >0.10.0</ version > </ dependency >
用法
声明性用法(自0.6.0起):
progressbar.wrap(collection, "TaskName")) {
…
// Progress will be automatically monitored by a progress bar
}\”>
// Looping over a collection: for ( T x : progressbar . wrap ( collection , \"TaskName\" )) { ... // Progress will be automatically monitored by a progress bar }
命令用法(因为0.7.0切换到Java的try-with-Resource模式):
progressbar ("Test", 100)) { // name, initial max
// Use progressbar ("Test", 100, progressbar Style.ASCII) if you want ASCII output style
for ( /* TASK TO TRACK */ ) {
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
}
} // progress bar stops automatically after completion of try-with-resource block\”>
// try-with-resource block try ( progressbar pb = new progressbar ( \"Test\" , 100 )) { // name, initial max // Use progressbar (\"Test\", 100, progressbar Style.ASCII) if you want ASCII output style for ( /* TASK TO TRACK */ ) { 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 } } // progress bar stops automatically after completion of try-with-resource block
新的0.9.0 :您现在可以将多个进度条用于并行作业:
progressbar ("Job1", max1);
progressbar pb2 = new progressbar ("Job2", max2)) { … }\”>
try ( progressbar pb1 = new progressbar ( \"Job1\" , max1 ); progressbar pb2 = new progressbar ( \"Job2\" , max2 )) { ... }
Kotlin扩展
Kotlin DSL样构建器可在ReimerSoftware/ progressbar -ktx上找到。
ChangElog
ChangElog
