diff options
author | Tavian Barnes <tavianator@gmail.com> | 2010-02-26 18:56:03 -0500 |
---|---|---|
committer | Tavian Barnes <tavianator@gmail.com> | 2010-02-26 18:56:03 -0500 |
commit | 5f4baeb85dbdb26ea56b214280eeb0f6233c1861 (patch) | |
tree | 1ec5bb757d96ced3a394fd53381165b10dac382b /dimension/progressbar.c | |
parent | cba6f44c5402991d859f5d24fbcc822f9c2c167d (diff) | |
download | dimension-5f4baeb85dbdb26ea56b214280eeb0f6233c1861.tar.xz |
Line up progress bars even when not in a terminal.
Diffstat (limited to 'dimension/progressbar.c')
-rw-r--r-- | dimension/progressbar.c | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/dimension/progressbar.c b/dimension/progressbar.c index c366d4d..6abcbd6 100644 --- a/dimension/progressbar.c +++ b/dimension/progressbar.c @@ -36,17 +36,16 @@ dmnsn_progressbar(const char *format, const dmnsn_progress *progress, ...) va_end(ap); - unsigned int increments = 48; + fflush(stdout); /* Try to fill the terminal with the progress bar; this is non-portable */ struct winsize ws; + unsigned int width = 80; if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws) == 0) { - increments = ws.ws_col - (len % ws.ws_col); + width = ws.ws_col; } - fflush(stdout); - - unsigned int i; + unsigned int i, increments = width - (len % width); for (i = 0; i < increments; ++i) { dmnsn_wait_progress(progress, ((double)(i + 1))/increments); |