* 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); fprintf(file, str);
if(needpad == 1) { if(needpad == 1) {
unsigned int i, cols = getcols(); int i, cols = getcols();
for(i=len; i < cols; ++i) { for(i=len; i < cols; ++i) {
fprintf(file, " "); fprintf(file, " ");
} }

View file

@ -53,7 +53,7 @@
extern config_t *config; extern config_t *config;
/* gets the current screen column width */ /* gets the current screen column width */
unsigned int getcols() int getcols()
{ {
if(!isatty(1)) { if(!isatty(1)) {
/* We will default to 80 columns if we're not a tty /* 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 /* 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; const char *p = str;
unsigned int cidx = indent; int cidx = indent;
while(*p) { while(*p) {
if(*p == ' ') { if(*p == ' ') {
@ -179,7 +179,7 @@ void indentprint(const char *str, unsigned int indent)
len = next - p; len = next - p;
if(len > (getcols() - cidx - 1)) { if(len > (getcols() - cidx - 1)) {
/* newline */ /* newline */
unsigned int i; int i;
fprintf(stdout, "\n"); fprintf(stdout, "\n");
for(i = 0; i < indent; i++) { for(i = 0; i < indent; i++) {
fprintf(stdout, " "); 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)) { for(i = list, cols = len; i; i = alpm_list_next(i)) {
char *str = alpm_list_getdata(i); char *str = alpm_list_getdata(i);
int s = strlen(str) + 2; int s = strlen(str) + 2;
unsigned int maxcols = getcols(); int maxcols = getcols();
if(s + cols >= maxcols) { if(s + cols >= maxcols) {
int i; int i;
cols = len; cols = len;
@ -385,11 +385,15 @@ void fill_progress(const int percent, const int proglen)
static unsigned int lasthash = 0, mouth = 0; static unsigned int lasthash = 0, mouth = 0;
unsigned int i; unsigned int i;
/* printf("\ndebug: proglen: %i\n", proglen); DEBUG*/
if(percent == 0) { if(percent == 0) {
lasthash = 0; lasthash = 0;
mouth = 0; mouth = 0;
} }
/* magic numbers, how I loathe thee */
if(proglen > 8) {
printf(" ["); printf(" [");
for(i = hashlen; i > 1; --i) { for(i = hashlen; i > 1; --i) {
/* if special progress bar enabled */ /* if special progress bar enabled */
@ -424,7 +428,12 @@ void fill_progress(const int percent, const int proglen)
printf("-"); printf("-");
} }
} }
printf("] %3d%%", percent); printf("]");
}
/* print percent after progress bar */
if(proglen > 5) {
printf(" %3d%%", percent);
}
if(percent == 100) { if(percent == 100) {
printf("\n"); printf("\n");
@ -434,5 +443,4 @@ void fill_progress(const int percent, const int proglen)
fflush(stdout); fflush(stdout);
} }
/* vim: set ts=2 sw=2 noet: */ /* vim: set ts=2 sw=2 noet: */

View file

@ -50,10 +50,10 @@
#define UPDATE_SPEED_SEC 0.2f #define UPDATE_SPEED_SEC 0.2f
#define _(str) gettext(str) #define _(str) gettext(str)
unsigned int getcols(); int getcols();
int makepath(char *path); int makepath(char *path);
int rmrf(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 *strtoupper(char *str);
char *strtrim(char *str); char *strtrim(char *str);
int reg_match(char *string, char *pattern); int reg_match(char *string, char *pattern);