progressBar: added eol for each progressBar update when no STDOUT_FILENO
This commit is contained in:
parent
2580aed994
commit
850c3d74e0
|
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "progressBar.hpp"
|
#include "progressBar.hpp"
|
||||||
|
|
@ -13,7 +14,7 @@
|
||||||
ProgressBar::ProgressBar(const std::string &mess, int maxValue,
|
ProgressBar::ProgressBar(const std::string &mess, int maxValue,
|
||||||
int progressLen, bool quiet): _mess(mess), _maxValue(maxValue),
|
int progressLen, bool quiet): _mess(mess), _maxValue(maxValue),
|
||||||
_progressLen(progressLen), last_time(std::chrono::system_clock::now()),
|
_progressLen(progressLen), last_time(std::chrono::system_clock::now()),
|
||||||
_quiet(quiet), _first(true)
|
_quiet(quiet), _first(true), _is_tty(isatty(STDOUT_FILENO) == 1)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -46,7 +47,7 @@ void ProgressBar::display(int value, char force)
|
||||||
fprintf(stdout, "%*s", (int)(_progressLen-nbEq), "");
|
fprintf(stdout, "%*s", (int)(_progressLen-nbEq), "");
|
||||||
char perc_str[11];
|
char perc_str[11];
|
||||||
snprintf(perc_str, sizeof(perc_str), "] %3.2f%%", percent);
|
snprintf(perc_str, sizeof(perc_str), "] %3.2f%%", percent);
|
||||||
printInfo(perc_str, false);
|
printInfo(perc_str, !_is_tty);
|
||||||
}
|
}
|
||||||
void ProgressBar::done()
|
void ProgressBar::done()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@ class ProgressBar {
|
||||||
std::chrono::time_point<std::chrono::system_clock> last_time;
|
std::chrono::time_point<std::chrono::system_clock> last_time;
|
||||||
bool _quiet;
|
bool _quiet;
|
||||||
bool _first;
|
bool _first;
|
||||||
|
bool _is_tty;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue