curl: progress bar refresh, get width using ioctl()
Get screen width from the environment variable COLUMNS first, if set. If not, use ioctl(). If nether works, assume 79. Closes #2242 The "refresh" is for the -# output when no total transfer size is known. It will now only use a single updated line even for this case: The "-=O=-" ship moves when data is transferred. The four flying "hashes" move (on a sine wave) on each refresh, independent of data.
- Loading branch information
- +89 −19 src/tool_cb_prg.c
- +4 −1 src/tool_cb_prg.h
- +2 −1 tests/runtests.pl
7 comments
on commit 993dd56
This comment has been minimized.
This comment has been minimized.
A
causes this Windows console wrap-error:
With a |
This comment has been minimized.
This comment has been minimized.
I've made a patch for Windows (doesn't rely on --- a/tool_cb_prg.c 2018-01-23 18:34:35
+++ b/tool_cb_prg.c 2018-01-23 20:33:11
@@ -202,6 +202,20 @@
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;
} |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Good. I had a hard time finding an URL which total transfer size is unknown. Do you have an rtmp stream with truly infinite size? I used this Chinese one |
This comment has been minimized.
This comment has been minimized.
Yeah, I had that problem too. I couldn't find any good URL that reliably would send something decently large without a size. I ended up setting up a hacky local HTTP server that respond without size, and then I could use |
This comment has been minimized.
This comment has been minimized.
|
This comment has been minimized.
This comment has been minimized.
Haha, that's just a lovely use of curl. You rock @jay! |
Shouldn't this be
fputs(buf, bar->out);
?