From 850c3d74e0580c7ffddea5738bc3914577c2b0fe Mon Sep 17 00:00:00 2001 From: Gwenhael Goavec-Merou Date: Tue, 26 Aug 2025 17:49:01 +0200 Subject: [PATCH] progressBar: added eol for each progressBar update when no STDOUT_FILENO --- src/progressBar.cpp | 5 +++-- src/progressBar.hpp | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/progressBar.cpp b/src/progressBar.cpp index 6df4878..14ab04f 100644 --- a/src/progressBar.cpp +++ b/src/progressBar.cpp @@ -5,6 +5,7 @@ #include #include +#include #include #include #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() { diff --git a/src/progressBar.hpp b/src/progressBar.hpp index 7a14f81..2d17367 100644 --- a/src/progressBar.hpp +++ b/src/progressBar.hpp @@ -23,6 +23,7 @@ class ProgressBar { std::chrono::time_point last_time; bool _quiet; bool _first; + bool _is_tty; }; #endif