From 5f4baeb85dbdb26ea56b214280eeb0f6233c1861 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Fri, 26 Feb 2010 18:56:03 -0500 Subject: Line up progress bars even when not in a terminal. --- dimension/progressbar.c | 9 ++++----- 1 file 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); -- cgit v1.2.3