--- poldek-0.18.6/vfile/vfprogress.c 2004-06-08 15:57:03.000000000 +0200 +++ poldek-0.18.6-patrys/vfile/vfprogress.c 2004-07-07 18:36:25.262259864 +0200 @@ -60,14 +60,15 @@ static int eta2str(char *buf, int bufsize, struct vf_progress_bar *bar) { - int mm, ss, n = 0; + int hh, mm, ss, n = 0; float eta = bar->eta + 0.5; - mm = (int)(eta / 60.0); + hh = (int)(eta / 60.0 / 60.00); + mm = (int)(eta / 60.0) % 60; ss = (int)eta % 60; if (mm || ss) - n = n_snprintf(&buf[n], bufsize - n, "%.2d:%.2d ETA", mm, ss); + n = n_snprintf(&buf[n], bufsize - n, "%.2d:%.2d:%.2d", hh, mm, ss); return n; } @@ -84,8 +85,6 @@ bar->transfer_rate = (float)amount / (current_time - bar->time_base); if (bar->transfer_rate > 0) bar->eta = (total - amount) / bar->transfer_rate; - - bar->transfer_rate /= 1024.0; } @@ -95,6 +94,7 @@ char line[256], outline[256], fmt[40]; float frac, percent; long n; + int screen_width = term_get_width(); if (bar->state == VF_PROGRESS_DISABLED) @@ -107,8 +107,18 @@ bar->state = VF_PROGRESS_DISABLED; return; } + + if (screen_width < 50) /* what kind of terminal is this?! */ + { + screen_width = 50; + } + if (screen_width > 255) /* this might cause problems */ + { + screen_width = 255; + } if (bar->state == VF_PROGRESS_VIRGIN) { + bar->width = screen_width - 49; /* calculate bar width = screen width - 8 - unit_line*/ if (total > 0) { if (total == amount || /* downloaded before progress() call */ total < 1024) { /* too small to show to */ @@ -142,7 +152,7 @@ return; } calculate_tt(total, amount, bar); - n_assert(bar->prev_n < 100); +// n_assert(bar->prev_n < 100); if (!bar->is_tty) { int k; @@ -159,18 +169,19 @@ } } else { - char unit_line[45], amount_str[16], total_str[16]; + char unit_line[42], amount_str[16], total_str[16], transfer_str[16]; int nn; nbytes2str(total_str, sizeof(total_str), total); nbytes2str(amount_str, sizeof(amount_str), amount); + nbytes2str(transfer_str, sizeof(transfer_str), bar->transfer_rate); if (total == amount) { if (bar->time_base == bar->time_last) /* fetched in less than 1s */ bar->transfer_rate = total / 1024.0; - nn = n_snprintf(unit_line, sizeof(unit_line), "[%s (%.1fK/s)]", - total_str, bar->transfer_rate); + nn = n_snprintf(unit_line, sizeof(unit_line), "[ %7s] [%7s/s]", + total_str, transfer_str); } else { int n = 0; char eta_str[64]; @@ -178,10 +189,9 @@ n = eta2str(eta_str, sizeof(eta_str), bar); nn = n_snprintf(unit_line, sizeof(unit_line), - "[%s of %s (%.1fK/s)%s%s]", - amount_str, total_str, bar->transfer_rate, - n ? ", ": "", - n ? eta_str : ""); + "[%7s/%7s] [%7s/s] [%8s]", + amount_str, total_str, transfer_str, + n ? eta_str : "--:--:--"); } if (nn > bar->maxlen) bar->maxlen = nn;