From 1e6de1f1dc19f992da570545a8ec253f7d02cf6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Mah=C3=A9?= Date: Mon, 16 Sep 2024 14:15:26 +0200 Subject: [PATCH 1/4] Add dynamic `MAX_PROGRESS_WIDTH` global variable to handle long lines Fix long line issue when using `uuu` outside of a terminal. eg: python.subprocess. --- uuu/uuu.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/uuu/uuu.cpp b/uuu/uuu.cpp index c1ad05af..3e736d24 100644 --- a/uuu/uuu.cpp +++ b/uuu/uuu.cpp @@ -56,6 +56,8 @@ const char * g_vt_red = "\x1B[91m"; const char * g_vt_kcyn = "\x1B[36m"; const char * g_vt_boldwhite = "\x1B[97m"; +size_t MAX_PROGRESS_WIDTH = 0; + void clean_vt_color() noexcept { g_vt_yellow = ""; @@ -323,9 +325,10 @@ string build_process_bar(size_t width, size_t pos, size_t total) void print_auto_scroll(string str, size_t len, size_t start) { + MAX_PROGRESS_WIDTH = max(str.size(), MAX_PROGRESS_WIDTH); if (str.size() <= len) { - str.resize(len, ' '); + str.resize(MAX_PROGRESS_WIDTH, ' '); cout << str; return; } @@ -600,7 +603,7 @@ void print_oneline(string str) } else { - str.resize(w, ' '); + str.resize(MAX_PROGRESS_WIDTH, ' '); } cout << str << endl; From a44633839db7de98db3453ceeb2e21b12283fb46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Mah=C3=A9?= Date: Wed, 18 Sep 2024 15:59:27 +0200 Subject: [PATCH 2/4] `MAX_PROGRESS_WIDTH` renamed to `g_max_process_width` --- uuu/uuu.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/uuu/uuu.cpp b/uuu/uuu.cpp index 3e736d24..4fe254bd 100644 --- a/uuu/uuu.cpp +++ b/uuu/uuu.cpp @@ -56,7 +56,7 @@ const char * g_vt_red = "\x1B[91m"; const char * g_vt_kcyn = "\x1B[36m"; const char * g_vt_boldwhite = "\x1B[97m"; -size_t MAX_PROGRESS_WIDTH = 0; +size_t g_max_process_width = 0; void clean_vt_color() noexcept { @@ -325,10 +325,10 @@ string build_process_bar(size_t width, size_t pos, size_t total) void print_auto_scroll(string str, size_t len, size_t start) { - MAX_PROGRESS_WIDTH = max(str.size(), MAX_PROGRESS_WIDTH); + g_max_process_width = max(str.size(), g_max_process_width); if (str.size() <= len) { - str.resize(MAX_PROGRESS_WIDTH, ' '); + str.resize(g_max_process_width, ' '); cout << str; return; } @@ -603,7 +603,7 @@ void print_oneline(string str) } else { - str.resize(MAX_PROGRESS_WIDTH, ' '); + str.resize(g_max_process_width, ' '); } cout << str << endl; From 9f5b4ca5f47c6c6747e60d6f4c0acb153be4ab17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Mah=C3=A9?= Date: Wed, 18 Sep 2024 16:03:58 +0200 Subject: [PATCH 3/4] `print_auto_scroll`: resize status when longer than console width --- uuu/uuu.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/uuu/uuu.cpp b/uuu/uuu.cpp index 4fe254bd..bd633e28 100644 --- a/uuu/uuu.cpp +++ b/uuu/uuu.cpp @@ -326,6 +326,7 @@ string build_process_bar(size_t width, size_t pos, size_t total) void print_auto_scroll(string str, size_t len, size_t start) { g_max_process_width = max(str.size(), g_max_process_width); + g_max_process_width = min(g_max_process_width, len); if (str.size() <= len) { str.resize(g_max_process_width, ' '); @@ -338,6 +339,13 @@ void print_auto_scroll(string str, size_t len, size_t start) else start = 0; + if (str.size() >= len){ + str.resize(len - 1); + str[str.size() - 1] = '.'; + str[str.size() - 2] = '.'; + str[str.size() - 3] = '.'; + } + string s = str.substr(start, len); s.resize(len, ' '); cout << s; @@ -594,6 +602,11 @@ void print_oneline(string str) if (w <= 3) return; + if (g_max_process_width == 0){ + g_max_process_width = str.size(); + g_max_process_width = min(g_max_process_width, w); + } + if (str.size() >= w) { str.resize(w - 1); @@ -657,7 +670,7 @@ int progress(uuu_notify nt, void *p) else { string_ex str; - str.format("\rSuccess %d Failure %d ", g_overall_okay, g_overall_failure); + str.format("\rSuccess %d Failure %d ", g_overall_okay, g_overall_failure); if (g_map_path_nt.empty()) str += "Wait for Known USB Device Appear..."; From fe17498b35d31448ce043d1b51ea04f413a44480 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Mah=C3=A9?= Date: Wed, 18 Sep 2024 17:40:24 +0200 Subject: [PATCH 4/4] Formatting & coding style format --- uuu/uuu.cpp | 77 ++++++++++++++++++++++++++--------------------------- 1 file changed, 38 insertions(+), 39 deletions(-) diff --git a/uuu/uuu.cpp b/uuu/uuu.cpp index bd633e28..3034d5ea 100644 --- a/uuu/uuu.cpp +++ b/uuu/uuu.cpp @@ -177,32 +177,32 @@ void print_help(bool detail = false) { const char help[] = "uuu [-d -m -v -V -bmap -no-bmap] <" "bootloader|cmdlists|cmd" ">\n\n" - " bootloader download bootloader to board by usb\n" - " cmdlist run all commands in cmdlist file\n" - " If it is path, search uuu.auto in dir\n" - " If it is zip, search uuu.auto in zip\n" - " cmd Run one command, use -H see detail\n" - " example: SDPS: boot -f flash.bin\n" - " -d Daemon mode, wait for forever.\n" - " -v -V verbose mode, -V enable libusb error\\warning info\n" - " -dry Dry run mode, check if script or cmd correct \n" - " -bmap Try using .bmap files even if flash commands do not specify them\n" - " -no-bmap Ignore .bmap files even if flash commands specify them\n" - " -m USBPATH Only monitor these paths.\n" - " -m 1:2 -m 1:3\n\n" - " -ms serial_no Monitor the serial number prefix of the device using 'serial_no'.\n" - " -t Timeout second for wait known usb device appeared\n" - " -T Timeout second for wait next known usb device appeared at stage switch\n" - " -e set environment variable key=value\n" - " -pp usb polling period in milliseconds\n" - " -dm disable small memory\n" - "uuu -s Enter shell mode. uuu.inputlog record all input commands\n" - " you can use \"uuu uuu.inputlog\" next time to run all commands\n\n" - "uuu -udev linux: show udev rule to avoid sudo each time \n" - "uuu -lsusb List connected know devices\n" + "\tbootloader download bootloader to board by usb\n" + "\tcmdlist\t run all commands in cmdlist file\n" + "\t\t\t\tIf it is path, search uuu.auto in dir\n" + "\t\t\t\tIf it is zip, search uuu.auto in zip\n" + "\tcmd\t\t Run one command, use -H see detail\n" + "\t\t\t\texample: SDPS: boot -f flash.bin\n" + "\t-d\t\t Daemon mode, wait for forever.\n" + "\t-v -V\t verbose mode, -V enable libusb error\\warning info\n" + "\t-dry\t\tDry run mode, check if script or cmd correct \n" + "\t-bmap\t Try using .bmap files even if flash commands do not specify them\n" + "\t-no-bmap\tIgnore .bmap files even if flash commands specify them\n" + "\t-m\t\t USBPATH Only monitor these paths.\n" + "\t\t\t\t\t-m 1:2 -m 1:3\n\n" + "\t-ms\t\t serial_no Monitor the serial number prefix of the device using 'serial_no'.\n" + "\t-t\t\t Timeout second for wait known usb device appeared\n" + "\t-T\t\t Timeout second for wait next known usb device appeared at stage switch\n" + "\t-e\t\t set environment variable key=value\n" + "\t-pp\t\t usb polling period in milliseconds\n" + "\t-dm\t\t disable small memory\n" + "uuu -s\t\t Enter shell mode. uuu.inputlog record all input commands\n" + "\t\t\t\tyou can use \"uuu uuu.inputlog\" next time to run all commands\n\n" + "uuu -udev\t linux: show udev rule to avoid sudo each time \n" + "uuu -lsusb\t List connected know devices\n" "uuu -IgSerNum Set windows registry to ignore USB serial number for known uuu devices\n" - "uuu -h show general help\n" - "uuu -H show general help and detailed help for commands\n\n"; + "uuu -h\t\t show general help\n" + "uuu -H\t\t show general help and detailed help for commands\n\n"; printf("%s", help); printf("uuu [-d -m -v -bmap -no-bmap] -b[run] "); g_BuildScripts.ShowCmds(); @@ -315,7 +315,7 @@ string build_process_bar(size_t width, size_t pos, size_t total) string_ex per; per.format("%d%%", pos * 100 / total); - + size_t start = (width - per.size()) / 2; str.replace(start, per.size(), per); str.insert(start, g_vt_yellow); @@ -325,8 +325,8 @@ string build_process_bar(size_t width, size_t pos, size_t total) void print_auto_scroll(string str, size_t len, size_t start) { - g_max_process_width = max(str.size(), g_max_process_width); - g_max_process_width = min(g_max_process_width, len); + g_max_process_width = max(str.size(), g_max_process_width); + g_max_process_width = min(g_max_process_width, len); if (str.size() <= len) { str.resize(g_max_process_width, ' '); @@ -339,12 +339,12 @@ void print_auto_scroll(string str, size_t len, size_t start) else start = 0; - if (str.size() >= len){ - str.resize(len - 1); - str[str.size() - 1] = '.'; - str[str.size() - 2] = '.'; - str[str.size() - 3] = '.'; - } + if (str.size() >= len){ + str.resize(len - 1); + str[str.size() - 1] = '.'; + str[str.size() - 2] = '.'; + str[str.size() - 3] = '.'; + } string s = str.substr(start, len); s.resize(len, ' '); @@ -445,7 +445,7 @@ class ShowNotify m_trans_pos = nt.index; return true; } - + if ((nt.index - m_trans_pos) < (m_trans_size / 100) && nt.index != m_trans_size) return false; @@ -602,10 +602,9 @@ void print_oneline(string str) if (w <= 3) return; - if (g_max_process_width == 0){ - g_max_process_width = str.size(); - g_max_process_width = min(g_max_process_width, w); - } + if (g_max_process_width == 0){ + g_max_process_width = min(str.size(), w); + } if (str.size() >= w) {