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 17, 2024
1 parent 54b900c commit 1e6de1f
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 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 @@ -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;
}
Expand Down Expand Up @@ -600,7 +603,7 @@ void print_oneline(string str)
}
else
{
str.resize(w, ' ');
str.resize(MAX_PROGRESS_WIDTH, ' ');
}
cout << str << endl;

Expand Down

0 comments on commit 1e6de1f

Please sign in to comment.