ctongfei / progressbar

Terminal-based progress bar for Java / JVM
http://tongfei.me/progressbar/
MIT License
1.08k stars 103 forks source link

Enable null ProgressBar #74

Closed koppor closed 4 years ago

koppor commented 4 years ago

When "code and fix"ing and application, I tend to use "Logger.debug", which doesn't appear at the console. - I would like to keep the ProgressBar-code, but just "disable" it. Think, the easiest way is to provide a "NullProgressBar", which hast the same interface as the normal ProgressBar, but outputs to "/dev/null" (i.e., does nothing).

ctongfei commented 4 years ago

Well in this case you could use new DelegateProgressBarConsumer(logger::debug)?

koppor commented 4 years ago

Thank you for the hint, I implemented it like that - and it works! 🎉

    try (ProgressBar progressBar = new ProgressBarBuilder()
      .setTaskName("Collect all files")
      .setInitialMax(100L)
      .setConsumer(new DelegatingProgressBarConsumer(x -> {}))
      .build();
    ) {

Maybe worth to add it into the documentation?