progressBar: added eol for each progressBar update when no STDOUT_FILENO

This commit is contained in:
Gwenhael Goavec-Merou 2025-08-26 17:49:01 +02:00
parent 2580aed994
commit 850c3d74e0
2 changed files with 4 additions and 2 deletions

View File

@ -5,6 +5,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <chrono>
#include <string>
#include "progressBar.hpp"
@ -13,7 +14,7 @@
ProgressBar::ProgressBar(const std::string &mess, int maxValue,
int progressLen, bool quiet): _mess(mess), _maxValue(maxValue),
_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), "");
char perc_str[11];
snprintf(perc_str, sizeof(perc_str), "] %3.2f%%", percent);
printInfo(perc_str, false);
printInfo(perc_str, !_is_tty);
}
void ProgressBar::done()
{

View File

@ -23,6 +23,7 @@ class ProgressBar {
std::chrono::time_point<std::chrono::system_clock> last_time;
bool _quiet;
bool _first;
bool _is_tty;
};
#endif