curl: make the progress bar detect terminal width changes
And up the widest supported bar to 400 columns. Fixes #14565 Reported-by: lolbinarycat on github Closes #14570
This commit is contained in:
parent
4e2f3641f8
commit
8f562f744c
@ -35,7 +35,8 @@
|
||||
|
||||
#include "memdebug.h" /* keep this as LAST include */
|
||||
|
||||
#define MAX_BARLENGTH 256
|
||||
#define MAX_BARLENGTH 400
|
||||
#define MIN_BARLENGTH 20
|
||||
|
||||
/* 200 values generated by this perl code:
|
||||
|
||||
@ -119,6 +120,17 @@ static void fly(struct ProgressData *bar, bool moved)
|
||||
# define CURL_OFF_T_MAX CURL_OFF_T_C(0x7FFFFFFFFFFFFFFF)
|
||||
#endif
|
||||
|
||||
static void update_width(struct ProgressData *bar)
|
||||
{
|
||||
int cols = get_terminal_columns();
|
||||
if(cols > MAX_BARLENGTH)
|
||||
bar->width = MAX_BARLENGTH;
|
||||
else if(cols > MIN_BARLENGTH)
|
||||
bar->width = (int)cols;
|
||||
else
|
||||
bar->width = MIN_BARLENGTH;
|
||||
}
|
||||
|
||||
int tool_progress_cb(void *clientp,
|
||||
curl_off_t dltotal, curl_off_t dlnow,
|
||||
curl_off_t ultotal, curl_off_t ulnow)
|
||||
@ -172,6 +184,7 @@ int tool_progress_cb(void *clientp,
|
||||
if(tvdiff(now, bar->prevtime) < 100L)
|
||||
/* limit progress-bar updating to 10 Hz */
|
||||
return 0;
|
||||
update_width(bar);
|
||||
fly(bar, point != bar->prev);
|
||||
}
|
||||
}
|
||||
@ -179,6 +192,7 @@ int tool_progress_cb(void *clientp,
|
||||
/* simply count invokes */
|
||||
bar->calls++;
|
||||
|
||||
update_width(bar);
|
||||
if((total > 0) && (point != bar->prev)) {
|
||||
char line[MAX_BARLENGTH + 1];
|
||||
char format[40];
|
||||
@ -223,7 +237,6 @@ int tool_progress_cb(void *clientp,
|
||||
void progressbarinit(struct ProgressData *bar,
|
||||
struct OperationConfig *config)
|
||||
{
|
||||
unsigned int cols;
|
||||
memset(bar, 0, sizeof(struct ProgressData));
|
||||
|
||||
/* pass the resume from value through to the progress function so it can
|
||||
@ -231,11 +244,7 @@ void progressbarinit(struct ProgressData *bar,
|
||||
if(config->use_resume)
|
||||
bar->initial_size = config->resume_from;
|
||||
|
||||
cols = get_terminal_columns();
|
||||
if(cols > MAX_BARLENGTH)
|
||||
bar->width = MAX_BARLENGTH;
|
||||
else if(cols > 20)
|
||||
bar->width = (int)cols;
|
||||
update_width(bar);
|
||||
|
||||
bar->out = tool_stderr;
|
||||
bar->tick = 150;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user