aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGisle Vanem <gisle.vanem@gmail.com>2018-01-23 22:41:50 +0100
committerDaniel Stenberg <daniel@haxx.se>2018-01-23 22:43:41 +0100
commita0b5e894455aed4624682064b511d6522af7e6b2 (patch)
treeb24e896c1baf6fb44c1cd053e2dca08ff1cddbca
parent65ceb20dfd3c1820b6af9c418a0ac2885dd6b4f2 (diff)
progress-bar: get screen width on windows
-rw-r--r--src/tool_cb_prg.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/tool_cb_prg.c b/src/tool_cb_prg.c
index dd8941631..cf3251b29 100644
--- a/src/tool_cb_prg.c
+++ b/src/tool_cb_prg.c
@@ -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;
}