Command line progress bar in Java

前端 未结 15 2010
[愿得一人]
[愿得一人] 2020-11-28 01:04

I have a Java program running in command line mode. I would like to display a progress bar, showing the percentage of job done. The same kind of progress bar you would see u

15条回答
  •  迷失自我
    2020-11-28 01:36

    There is https://github.com/ctongfei/progressbar, License: MIT

    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:

    
      me.tongfei
      progressbar
      0.5.5
    
    

    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 bar
    

提交回复
热议问题