]> granicus.if.org Git - curl/commitdiff
progress-bar: get screen width on windows
authorGisle Vanem <gisle.vanem@gmail.com>
Tue, 23 Jan 2018 21:41:50 +0000 (22:41 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Tue, 23 Jan 2018 21:43:41 +0000 (22:43 +0100)
src/tool_cb_prg.c

index dd89416317abd413176d67f135ffc3454399284a..cf3251b2999545e6abba248188a4b0950eec074e 100644 (file)
@@ -202,6 +202,21 @@ void progressbarinit(struct ProgressData *bar,
     struct winsize ts;
     if(!ioctl(STDIN_FILENO, TIOCGWINSZ, &ts))
       cols = ts.ws_col;
+#elif defined(_WIN32)
+    {
+      HANDLE  stderr_hnd = GetStdHandle(STD_ERROR_HANDLE);
+      CONSOLE_SCREEN_BUFFER_INFO console_info;
+
+      if((stderr_hnd != INVALID_HANDLE_VALUE) &&
+         GetConsoleScreenBufferInfo(stderr_hnd, &console_info)) {
+        /*
+         * Do not use +1 to get the true screen-width since writing a
+         * character at the right edge will cause a line wrap.
+         */
+        cols = (int)
+          (console_info.srWindow.Right - console_info.srWindow.Left);
+      }
+    }
 #endif /* TIOCGSIZE */
     bar->width = cols;
   }