Date: Tuesday, March 13, 2007 @ 12:15:38 Author: dan Path: /home/cvs-pacman/pacman-lib/src/pacman Modified: log.c (1.33 -> 1.34) util.c (1.31 -> 1.32) util.h (1.17 -> 1.18) * Resizing terminal while progress bars were displayed caused some weird issues, this should fix it. Progress bars now go from displaying, to showing percent only, to not displaying at all. Changed unsigned -> signed to prevent wraparound errors in integer comparison. --------+ log.c | 2 - util.c | 76 ++++++++++++++++++++++++++++++++++----------------------------- util.h | 4 +-- 3 files changed, 45 insertions(+), 37 deletions(-) Index: pacman-lib/src/pacman/log.c diff -u pacman-lib/src/pacman/log.c:1.33 pacman-lib/src/pacman/log.c:1.34 --- pacman-lib/src/pacman/log.c:1.33 Wed Mar 7 02:45:31 2007 +++ pacman-lib/src/pacman/log.c Tue Mar 13 12:15:38 2007 @@ -134,7 +134,7 @@ fprintf(file, str); if(needpad == 1) { - unsigned int i, cols = getcols(); + int i, cols = getcols(); for(i=len; i < cols; ++i) { fprintf(file, " "); } Index: pacman-lib/src/pacman/util.c diff -u pacman-lib/src/pacman/util.c:1.31 pacman-lib/src/pacman/util.c:1.32 --- pacman-lib/src/pacman/util.c:1.31 Mon Mar 5 17:13:35 2007 +++ pacman-lib/src/pacman/util.c Tue Mar 13 12:15:38 2007 @@ -53,7 +53,7 @@ extern config_t *config; /* gets the current screen column width */ -unsigned int getcols() +int getcols() { if(!isatty(1)) { /* We will default to 80 columns if we're not a tty @@ -161,10 +161,10 @@ /* output a string, but wrap words properly with a specified indentation */ -void indentprint(const char *str, unsigned int indent) +void indentprint(const char *str, int indent) { const char *p = str; - unsigned int cidx = indent; + int cidx = indent; while(*p) { if(*p == ' ') { @@ -177,9 +177,9 @@ next = p + strlen(p); } len = next - p; - if(len > (getcols()-cidx-1)) { + if(len > (getcols() - cidx - 1)) { /* newline */ - unsigned int i; + int i; fprintf(stdout, "\n"); for(i = 0; i < indent; i++) { fprintf(stdout, " "); @@ -242,7 +242,7 @@ for(i = list, cols = len; i; i = alpm_list_next(i)) { char *str = alpm_list_getdata(i); int s = strlen(str) + 2; - unsigned int maxcols = getcols(); + int maxcols = getcols(); if(s + cols >= maxcols) { int i; cols = len; @@ -385,46 +385,55 @@ static unsigned int lasthash = 0, mouth = 0; unsigned int i; + /* printf("\ndebug: proglen: %i\n", proglen); DEBUG*/ + if(percent == 0) { lasthash = 0; mouth = 0; } - printf(" ["); - for(i = hashlen; i > 1; --i) { - /* if special progress bar enabled */ - if(chomp) { - if(i > hashlen - hash) { - printf("-"); - } else if(i == hashlen - hash) { - if(lasthash == hash) { - if(mouth) { - printf("\033[1;33mC\033[m"); + /* magic numbers, how I loathe thee */ + if(proglen > 8) { + printf(" ["); + for(i = hashlen; i > 1; --i) { + /* if special progress bar enabled */ + if(chomp) { + if(i > hashlen - hash) { + printf("-"); + } else if(i == hashlen - hash) { + if(lasthash == hash) { + if(mouth) { + printf("\033[1;33mC\033[m"); + } else { + printf("\033[1;33mc\033[m"); + } } else { - printf("\033[1;33mc\033[m"); + lasthash = hash; + mouth = mouth == 1 ? 0 : 1; + if(mouth) { + printf("\033[1;33mC\033[m"); + } else { + printf("\033[1;33mc\033[m"); + } } + } else if(i%3 == 0) { + printf("\033[0;37mo\033[m"); } else { - lasthash = hash; - mouth = mouth == 1 ? 0 : 1; - if(mouth) { - printf("\033[1;33mC\033[m"); - } else { - printf("\033[1;33mc\033[m"); - } + printf("\033[0;37m \033[m"); } - } else if(i%3 == 0) { - printf("\033[0;37mo\033[m"); + } /* else regular progress bar */ + else if(i > hashlen - hash) { + printf("#"); } else { - printf("\033[0;37m \033[m"); + printf("-"); } - } /* else regular progress bar */ - else if(i > hashlen - hash) { - printf("#"); - } else { - printf("-"); } + printf("]"); + } + /* print percent after progress bar */ + if(proglen > 5) { + printf(" %3d%%", percent); } - printf("] %3d%%", percent); if(percent == 100) { printf("\n"); @@ -434,5 +443,4 @@ fflush(stdout); } - /* vim: set ts=2 sw=2 noet: */ Index: pacman-lib/src/pacman/util.h diff -u pacman-lib/src/pacman/util.h:1.17 pacman-lib/src/pacman/util.h:1.18 --- pacman-lib/src/pacman/util.h:1.17 Mon Mar 5 20:21:42 2007 +++ pacman-lib/src/pacman/util.h Tue Mar 13 12:15:38 2007 @@ -50,10 +50,10 @@ #define UPDATE_SPEED_SEC 0.2f #define _(str) gettext(str) -unsigned int getcols(); +int getcols(); int makepath(char *path); int rmrf(char *path); -void indentprint(const char *str, unsigned int indent); +void indentprint(const char *str, int indent); char *strtoupper(char *str); char *strtrim(char *str); int reg_match(char *string, char *pattern);