diff --git a/src/main.cpp b/src/main.cpp index d073ba3..bfeaa28 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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(verbose)) ("verbose-level", "verbose level -1: quiet, 0: normal, 1:verbose, 2:debug", cxxopts::value(verbose_level)) + ("force-terminal-mode", + "force progress bar output as if connected to a terminal", + cxxopts::value(args->force_terminal_mode)) ("h,help", "Give this help list") ("verify", "Verify write operation (SPI Flash only)", cxxopts::value(args->verify)) diff --git a/src/progressBar.cpp b/src/progressBar.cpp index 14ab04f..c25ea3a 100644 --- a/src/progressBar.cpp +++ b/src/progressBar.cpp @@ -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) { diff --git a/src/progressBar.hpp b/src/progressBar.hpp index 2d17367..e8db37e 100644 --- a/src/progressBar.hpp +++ b/src/progressBar.hpp @@ -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