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
#include "jtag.hpp"
#include "part.hpp"
#include "progressBar.hpp"
#include "spiFlash.hpp"
#include "rawParser.hpp"
#ifdef ENABLE_XILINX_SUPPORT
@ -72,6 +73,7 @@ using namespace std;
struct arguments {
int8_t verbose;
bool force_terminal_mode;
bool reset, detect, detect_flash, verify, scan_usb;
unsigned int offset;
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};
/* command line args. */
struct arguments args = {0,
struct arguments args = {
/* verbose, force_terminal_mode */
0, false,
//reset, detect, detect_flash, verify, scan_usb
false, false, false, false, false,
0, "", "", "", "-", "", -1,
@ -172,6 +176,9 @@ int main(int argc, char **argv)
if (ret != 0)
return (ret == 1) ? EXIT_SUCCESS : EXIT_FAILURE;
if (args.force_terminal_mode)
ProgressBar::setForceTerminalMode();
if (args.is_list_command) {
displaySupported(args);
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))
("verbose-level", "verbose level -1: quiet, 0: normal, 1:verbose, 2:debug",
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")
("verify", "Verify write operation (SPI Flash only)",
cxxopts::value<bool>(args->verify))

View File

@ -11,13 +11,21 @@
#include "progressBar.hpp"
#include "display.hpp"
bool ProgressBar::_force_terminal_mode = false;
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), _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)
{
if (_quiet) {

View File

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