summaryrefslogtreecommitdiffstats
path: root/dimension
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@gmail.com>2010-02-26 18:56:03 -0500
committerTavian Barnes <tavianator@gmail.com>2010-02-26 18:56:03 -0500
commit5f4baeb85dbdb26ea56b214280eeb0f6233c1861 (patch)
tree1ec5bb757d96ced3a394fd53381165b10dac382b /dimension
parentcba6f44c5402991d859f5d24fbcc822f9c2c167d (diff)
downloaddimension-5f4baeb85dbdb26ea56b214280eeb0f6233c1861.tar.xz
Line up progress bars even when not in a terminal.
Diffstat (limited to 'dimension')
-rw-r--r--dimension/progressbar.c9
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);