Skip to content
Merged
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
27 changes: 20 additions & 7 deletions uuu/uuu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ const char * g_vt_red = "\x1B[91m";
const char * g_vt_kcyn = "\x1B[36m";
const char * g_vt_boldwhite = "\x1B[97m";

int g_failback_console_width = 300;

size_t g_max_process_width = 0;

void clean_vt_color() noexcept
Expand Down Expand Up @@ -600,12 +598,12 @@ mutex g_callback_mutex;

void print_oneline(string str)
{
size_t w = get_console_width();
int w = get_console_width();
if (w <= 3)
return;

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

if (str.size() >= w)
Expand Down Expand Up @@ -767,7 +765,8 @@ bool enable_vt_mode()
int get_console_width()
{
CONSOLE_SCREEN_BUFFER_INFO sbInfo;
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &sbInfo);
if (!GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &sbInfo))
return -1;
return sbInfo.dwSize.X;
}
#else
Expand All @@ -776,10 +775,11 @@ bool enable_vt_mode() { return true; }
int get_console_width()
{
struct winsize w;
if (ioctl(0, TIOCGWINSZ, &w) == -1)
if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &w) == -1)
{
return g_failback_console_width;
return -1;
}

return w.ws_col;
}
#endif
Expand Down Expand Up @@ -1154,6 +1154,19 @@ int main(int argc, char **argv)
}
}

#ifndef _WIN32
if (!g_verbose && !isatty(STDOUT_FILENO)) {
cout << "stdout is not a TTY. Using verbose mode" << endl;
g_verbose = 1;
}
#endif

if (!g_verbose && get_console_width() <= 3)
{
cout << "Failed to get terminal width, or terminal width too small. Using verbose mode" << endl;
g_verbose = 1;
}

signal(SIGINT, ctrl_c_handle);

uuu_set_askpasswd(ask_passwd);
Expand Down
Loading