progressBar: use color

This commit is contained in:
Gwenhael Goavec-Merou 2019-11-20 07:51:37 +01:00
parent e05126e1e1
commit 04624f028d
2 changed files with 14 additions and 3 deletions

View File

@ -18,6 +18,7 @@
#include <stdio.h>
#include <stdlib.h>
#include "progressBar.hpp"
#include "display.hpp"
ProgressBar::ProgressBar(std::string mess, int maxValue, int progressLen):
_mess(mess), _maxValue(maxValue), _progressLen(progressLen)
@ -29,15 +30,24 @@ void ProgressBar::display(int value)
float percent = ((float)value * 100.0f)/(float)_maxValue;
float nbEq = (percent * (float) _progressLen)/100.0f;
fprintf(stderr, "\r%s: [", _mess.c_str());
//fprintf(stderr, "\r%s: [", _mess.c_str());
printInfo("\r" + _mess + ": [", false);
for (int z=0; z < nbEq; z++) {
fputc('=', stderr);
}
fprintf(stderr, "%*s", (int)(_progressLen-nbEq), "");
fprintf(stderr, "] %3.2f%%", percent);
//fprintf(stderr, "] %3.2f%%", percent);
printInfo("] " + std::to_string(percent) + "%", false);
}
void ProgressBar::done()
{
display(_maxValue);
fprintf(stderr, "\nDone\n");
//fprintf(stderr, "\nDone\n");
printSuccess("\nDone");
}
void ProgressBar::fail()
{
display(_maxValue);
//fprintf(stderr, "\nDone\n");
printSuccess("\nFail");
}

View File

@ -25,6 +25,7 @@ class ProgressBar {
ProgressBar(std::string mess, int maxValue, int progressLen);
void display(int value);
void done();
void fail();
private:
std::string _mess;
int _maxValue;