Skip to content

Commit

Permalink
Add dynamic MAX_PROGRESS_WIDTH global variable to handle long lines
Browse files Browse the repository at this point in the history
Fix long line issue when using `uuu` outside of a terminal. eg: python.subprocess.
  • Loading branch information
thmahe committed Sep 16, 2024
1 parent 54b900c commit c3a23e4
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 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 MAX_PROGRESS_WIDTH = 0;

void clean_vt_color() noexcept
{
g_vt_yellow = "";
Expand Down Expand Up @@ -275,6 +277,10 @@ int g_overall_failure;
char g_wait[] = "|/-\\";
int g_wait_index;

void trim_string_at_first(string str, char at_first){
size_t max_index = str.find_first_of(at_first);
str.resize(max_index);
}

string build_process_bar(size_t width, size_t pos, size_t total)
{
Expand Down Expand Up @@ -323,9 +329,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;
}
Expand Down Expand Up @@ -600,7 +607,7 @@ void print_oneline(string str)
}
else
{
str.resize(w, ' ');
str.resize(MAX_PROGRESS_WIDTH, ' ');
}
cout << str << endl;

Expand Down

0 comments on commit c3a23e4

Please sign in to comment.