Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dynamic MAX_PROGRESS_WIDTH global variable to handle long lines #435

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 45 additions & 30 deletions uuu/uuu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 g_max_process_width = 0;

void clean_vt_color() noexcept
{
g_vt_yellow = "";
Expand Down Expand Up @@ -175,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();
Expand Down Expand Up @@ -313,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);
Expand All @@ -323,9 +325,11 @@ 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)
thmahe marked this conversation as resolved.
Show resolved Hide resolved
{
str.resize(len, ' ');
str.resize(g_max_process_width, ' ');
cout << str;
return;
}
Expand All @@ -335,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;
Expand Down Expand Up @@ -434,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;
Expand Down Expand Up @@ -591,6 +602,10 @@ void print_oneline(string str)
if (w <= 3)
return;

if (g_max_process_width == 0){
g_max_process_width = min(str.size(), w);
}

if (str.size() >= w)
{
str.resize(w - 1);
Expand All @@ -600,7 +615,7 @@ void print_oneline(string str)
}
else
{
str.resize(w, ' ');
str.resize(g_max_process_width, ' ');
}
cout << str << endl;

Expand Down Expand Up @@ -654,7 +669,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);

thmahe marked this conversation as resolved.
Show resolved Hide resolved
if (g_map_path_nt.empty())
str += "Wait for Known USB Device Appear...";
Expand Down