summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2018-01-20 13:40:22 +0100
committerDaniel Stenberg <daniel@haxx.se>2018-01-20 13:40:22 +0100
commitd8719b864bd15a9863d69109063f1aada20e0704 (patch)
tree15af4d5da80b4a4ff25f816871a3b49561e0c111
parent126b579f656d968c9f6ab02fc7e6a0124d267044 (diff)
downloadcurl-bagder/progress-bar-fly.tar.gz
fixup: let COLUMNS be first choice, then ioctl()bagder/progress-bar-fly
... and make the test suite set fixed 79 columns.
-rw-r--r--src/tool_cb_prg.c52
-rwxr-xr-xtests/runtests.pl3
2 files changed, 27 insertions, 28 deletions
diff --git a/src/tool_cb_prg.c b/src/tool_cb_prg.c
index 232e370ea..dd8941631 100644
--- a/src/tool_cb_prg.c
+++ b/src/tool_cb_prg.c
@@ -173,18 +173,7 @@ int tool_progress_cb(void *clientp,
void progressbarinit(struct ProgressData *bar,
struct OperationConfig *config)
{
- int cols = 0;
-
-#ifdef TIOCGSIZE
- struct ttysize ts;
- if(!ioctl(STDIN_FILENO, TIOCGSIZE, &ts))
- cols = ts.ts_cols;
-#elif defined(TIOCGWINSZ)
- struct winsize ts;
- if(!ioctl(STDIN_FILENO, TIOCGWINSZ, &ts))
- cols = ts.ws_col;
-#endif /* TIOCGSIZE */
-
+ char *colp;
memset(bar, 0, sizeof(struct ProgressData));
/* pass this through to progress function so
@@ -193,24 +182,33 @@ void progressbarinit(struct ProgressData *bar,
if(config->use_resume)
bar->initial_size = config->resume_from;
- if(!cols) {
- char *colp = curlx_getenv("COLUMNS");
- if(colp) {
- char *endptr;
- long num = strtol(colp, &endptr, 10);
- if((endptr != colp) && (endptr == colp + strlen(colp)) && (num > 0))
- bar->width = (int)num;
- else
- bar->width = 79;
- curl_free(colp);
- }
- else
- bar->width = 79;
+ colp = curlx_getenv("COLUMNS");
+ if(colp) {
+ char *endptr;
+ long num = strtol(colp, &endptr, 10);
+ if((endptr != colp) && (endptr == colp + strlen(colp)) && (num > 20))
+ bar->width = (int)num;
+ curl_free(colp);
}
- else
+
+ if(!bar->width) {
+ int cols = 0;
+
+#ifdef TIOCGSIZE
+ struct ttysize ts;
+ if(!ioctl(STDIN_FILENO, TIOCGSIZE, &ts))
+ cols = ts.ts_cols;
+#elif defined(TIOCGWINSZ)
+ struct winsize ts;
+ if(!ioctl(STDIN_FILENO, TIOCGWINSZ, &ts))
+ cols = ts.ws_col;
+#endif /* TIOCGSIZE */
bar->width = cols;
+ }
- if(bar->width > MAX_BARLENGTH)
+ if(!bar->width)
+ bar->width = 79;
+ else if(bar->width > MAX_BARLENGTH)
bar->width = MAX_BARLENGTH;
bar->out = config->global->errors;
diff --git a/tests/runtests.pl b/tests/runtests.pl
index dcd9f8419..d68c20f19 100755
--- a/tests/runtests.pl
+++ b/tests/runtests.pl
@@ -6,7 +6,7 @@
# | (__| |_| | _ <| |___
# \___|\___/|_| \_\_____|
#
-# Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
+# Copyright (C) 1998 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al.
#
# This software is licensed as described in the file COPYING, which
# you should have received as part of this distribution. The terms
@@ -340,6 +340,7 @@ $ENV{'CURL_MEMDEBUG'} = $memdump;
$ENV{'CURL_ENTROPY'}="12345678";
$ENV{'CURL_FORCETIME'}=1; # for debug NTLM magic
$ENV{'HOME'}=$pwd;
+$ENV{'COLUMNS'}=79; # screen width!
sub catch_zap {
my $signame = shift;