Mpdreamz / shellprogressbar

ShellProgressBar - display progress in your console application
MIT License
1.44k stars 134 forks source link

Feature request: Set progress by percentage #65

Closed KoalaBear84 closed 3 years ago

KoalaBear84 commented 4 years ago

I would like to set the progress by percentage.

Something like this:

// Set progress to 10.7%
ProgressBar.SetPercentage(10.7);
// or
ProgressBar.SetPercentage(10.7m);

Currently using hardcoded 1000 ticks and:

ProgressBar.Tick((int)(progress / 0.1m));

Also would be nice to support a single digits after the comma separator, so it will display "10.7%" instead of "10.70%". Also because it's faster to read, and not as

Thanks!

0xced commented 4 years ago

You can already achieve this by using AsProgress<float>() which returns an IProgress<float> that you can use to report progression as percentage:

using var progressBar = new ProgressBar(10000, "My Progress Message");
var progress = progressBar.AsProgress<float>();
progress.Report(0.107); // 10.7%
KoalaBear84 commented 4 years ago

Thanks, if this could be added to the readme it would be nice.