* 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.
This commit is contained in:
Dan McGee 2007-03-13 16:15:38 +00:00
parent 2020e0ec73
commit 6e05ad1d24
3 changed files with 45 additions and 37 deletions

View File

@ -134,7 +134,7 @@ void pm_fprintf(FILE *file, unsigned short line, char *fmt, ...)
fprintf(file, str);
if(needpad == 1) {
unsigned int i, cols = getcols();
int i, cols = getcols();
for(i=len; i < cols; ++i) {
fprintf(file, " ");
}

View File

@ -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 @@ int rmrf(char *path)
/* 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 @@ void indentprint(const char *str, unsigned int indent)
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 @@ void list_display(const char *title, alpm_list_t *list)
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 @@ void fill_progress(const int percent, const int proglen)
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 @@ void fill_progress(const int percent, const int proglen)
fflush(stdout);
}
/* vim: set ts=2 sw=2 noet: */

View File

@ -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);