main,progressBar: --force-terminal-mode argument to force progress bar output as if connected to a terminal (#629)

This commit is contained in:
Gwenhael Goavec-Merou 2026-03-13 09:28:54 +01:00
parent 9d6cc15f51
commit 28efd18798
3 changed files with 22 additions and 2 deletions

View File

@ -54,6 +54,7 @@
#endif #endif
#include "jtag.hpp" #include "jtag.hpp"
#include "part.hpp" #include "part.hpp"
#include "progressBar.hpp"
#include "spiFlash.hpp" #include "spiFlash.hpp"
#include "rawParser.hpp" #include "rawParser.hpp"
#ifdef ENABLE_XILINX_SUPPORT #ifdef ENABLE_XILINX_SUPPORT
@ -72,6 +73,7 @@ using namespace std;
struct arguments { struct arguments {
int8_t verbose; int8_t verbose;
bool force_terminal_mode;
bool reset, detect, detect_flash, verify, scan_usb; bool reset, detect, detect_flash, verify, scan_usb;
unsigned int offset; unsigned int offset;
string bit_file; string bit_file;
@ -149,7 +151,9 @@ int main(int argc, char **argv)
jtag_pins_conf_t pins_config = {0, 0, 0, 0, 0, 0}; jtag_pins_conf_t pins_config = {0, 0, 0, 0, 0, 0};
/* command line args. */ /* command line args. */
struct arguments args = {0, struct arguments args = {
/* verbose, force_terminal_mode */
0, false,
//reset, detect, detect_flash, verify, scan_usb //reset, detect, detect_flash, verify, scan_usb
false, false, false, false, false, false, false, false, false, false,
0, "", "", "", "-", "", -1, 0, "", "", "", "-", "", -1,
@ -172,6 +176,9 @@ int main(int argc, char **argv)
if (ret != 0) if (ret != 0)
return (ret == 1) ? EXIT_SUCCESS : EXIT_FAILURE; return (ret == 1) ? EXIT_SUCCESS : EXIT_FAILURE;
if (args.force_terminal_mode)
ProgressBar::setForceTerminalMode();
if (args.is_list_command) { if (args.is_list_command) {
displaySupported(args); displaySupported(args);
return EXIT_SUCCESS; return EXIT_SUCCESS;
@ -998,6 +1005,9 @@ int parse_opt(int argc, char **argv, struct arguments *args,
("v,verbose", "Produce verbose output", cxxopts::value<bool>(verbose)) ("v,verbose", "Produce verbose output", cxxopts::value<bool>(verbose))
("verbose-level", "verbose level -1: quiet, 0: normal, 1:verbose, 2:debug", ("verbose-level", "verbose level -1: quiet, 0: normal, 1:verbose, 2:debug",
cxxopts::value<int8_t>(verbose_level)) cxxopts::value<int8_t>(verbose_level))
("force-terminal-mode",
"force progress bar output as if connected to a terminal",
cxxopts::value<bool>(args->force_terminal_mode))
("h,help", "Give this help list") ("h,help", "Give this help list")
("verify", "Verify write operation (SPI Flash only)", ("verify", "Verify write operation (SPI Flash only)",
cxxopts::value<bool>(args->verify)) cxxopts::value<bool>(args->verify))

View File

@ -11,13 +11,21 @@
#include "progressBar.hpp" #include "progressBar.hpp"
#include "display.hpp" #include "display.hpp"
bool ProgressBar::_force_terminal_mode = false;
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), _is_tty(isatty(STDOUT_FILENO) == 1) _quiet(quiet), _first(true),
_is_tty(_force_terminal_mode || isatty(STDOUT_FILENO) == 1)
{ {
} }
void ProgressBar::setForceTerminalMode()
{
_force_terminal_mode = true;
}
void ProgressBar::display(int value, char force) void ProgressBar::display(int value, char force)
{ {
if (_quiet) { if (_quiet) {

View File

@ -12,6 +12,7 @@ class ProgressBar {
public: public:
ProgressBar(const std::string &mess, int maxValue, int progressLen, ProgressBar(const std::string &mess, int maxValue, int progressLen,
bool quiet = false); bool quiet = false);
static void setForceTerminalMode();
void display(int value, char force = 0); void display(int value, char force = 0);
void done(); void done();
void fail(); void fail();
@ -24,6 +25,7 @@ class ProgressBar {
bool _quiet; bool _quiet;
bool _first; bool _first;
bool _is_tty; bool _is_tty;
static bool _force_terminal_mode;
}; };
#endif #endif