]>
Commit | Line | Data |
---|---|---|
6f1b9640 PZ |
1 | --- poldek-0.18.6/vfile/vfprogress.c 2004-06-08 15:57:03.000000000 +0200 |
2 | +++ poldek-0.18.6-patrys/vfile/vfprogress.c 2004-07-07 18:36:25.262259864 +0200 | |
3 | @@ -60,14 +60,15 @@ | |
4 | ||
5 | static int eta2str(char *buf, int bufsize, struct vf_progress_bar *bar) | |
6 | { | |
7 | - int mm, ss, n = 0; | |
8 | + int hh, mm, ss, n = 0; | |
9 | float eta = bar->eta + 0.5; | |
10 | ||
11 | ||
12 | - mm = (int)(eta / 60.0); | |
13 | + hh = (int)(eta / 60.0 / 60.00); | |
14 | + mm = (int)(eta / 60.0) % 60; | |
15 | ss = (int)eta % 60; | |
16 | if (mm || ss) | |
17 | - n = n_snprintf(&buf[n], bufsize - n, "%.2d:%.2d ETA", mm, ss); | |
18 | + n = n_snprintf(&buf[n], bufsize - n, "%.2d:%.2d:%.2d", hh, mm, ss); | |
19 | return n; | |
20 | } | |
21 | ||
22 | @@ -84,8 +85,6 @@ | |
23 | bar->transfer_rate = (float)amount / (current_time - bar->time_base); | |
24 | if (bar->transfer_rate > 0) | |
25 | bar->eta = (total - amount) / bar->transfer_rate; | |
26 | - | |
27 | - bar->transfer_rate /= 1024.0; | |
28 | } | |
29 | ||
30 | ||
31 | @@ -95,6 +94,7 @@ | |
32 | char line[256], outline[256], fmt[40]; | |
33 | float frac, percent; | |
34 | long n; | |
25e388c1 | 35 | + int screen_width = term_get_width(); |
6f1b9640 | 36 | |
25e388c1 PZ |
37 | |
38 | if (bar->state == VF_PROGRESS_DISABLED) | |
6f1b9640 | 39 | @@ -107,8 +107,18 @@ |
25e388c1 PZ |
40 | bar->state = VF_PROGRESS_DISABLED; |
41 | return; | |
42 | } | |
43 | + | |
44 | + if (screen_width < 50) /* what kind of terminal is this?! */ | |
45 | + { | |
46 | + screen_width = 50; | |
9c2791f6 PZ |
47 | + } |
48 | + if (screen_width > 255) /* this might cause problems */ | |
49 | + { | |
50 | + screen_width = 255; | |
25e388c1 PZ |
51 | + } |
52 | ||
53 | if (bar->state == VF_PROGRESS_VIRGIN) { | |
6f1b9640 | 54 | + bar->width = screen_width - 49; /* calculate bar width = screen width - 8 - unit_line*/ |
25e388c1 PZ |
55 | if (total > 0) { |
56 | if (total == amount || /* downloaded before progress() call */ | |
57 | total < 1024) { /* too small to show to */ | |
6f1b9640 | 58 | @@ -142,7 +152,7 @@ |
40ed15cb PZ |
59 | return; |
60 | } | |
6f1b9640 | 61 | calculate_tt(total, amount, bar); |
3286be84 | 62 | - n_assert(bar->prev_n < 100); |
6f1b9640 | 63 | +// n_assert(bar->prev_n < 100); |
40ed15cb | 64 | if (!bar->is_tty) { |
25e388c1 PZ |
65 | int k; |
66 | ||
6f1b9640 | 67 | @@ -159,18 +169,19 @@ |
25e388c1 PZ |
68 | } |
69 | ||
70 | } else { | |
6f1b9640 | 71 | - char unit_line[45], amount_str[16], total_str[16]; |
b4cecb9b | 72 | + char unit_line[42], amount_str[16], total_str[16], transfer_str[16]; |
6f1b9640 PZ |
73 | int nn; |
74 | ||
25e388c1 PZ |
75 | nbytes2str(total_str, sizeof(total_str), total); |
76 | nbytes2str(amount_str, sizeof(amount_str), amount); | |
6f1b9640 | 77 | + nbytes2str(transfer_str, sizeof(transfer_str), bar->transfer_rate); |
25e388c1 | 78 | |
6f1b9640 PZ |
79 | if (total == amount) { |
80 | if (bar->time_base == bar->time_last) /* fetched in less than 1s */ | |
81 | bar->transfer_rate = total / 1024.0; | |
82 | ||
83 | - nn = n_snprintf(unit_line, sizeof(unit_line), "[%s (%.1fK/s)]", | |
84 | - total_str, bar->transfer_rate); | |
85 | + nn = n_snprintf(unit_line, sizeof(unit_line), "[ %7s] [%7s/s]", | |
86 | + total_str, transfer_str); | |
87 | } else { | |
88 | int n = 0; | |
89 | char eta_str[64]; | |
90 | @@ -178,10 +189,9 @@ | |
91 | n = eta2str(eta_str, sizeof(eta_str), bar); | |
92 | ||
93 | nn = n_snprintf(unit_line, sizeof(unit_line), | |
94 | - "[%s of %s (%.1fK/s)%s%s]", | |
95 | - amount_str, total_str, bar->transfer_rate, | |
96 | - n ? ", ": "", | |
97 | - n ? eta_str : ""); | |
98 | + "[%7s/%7s] [%7s/s] [%8s]", | |
99 | + amount_str, total_str, transfer_str, | |
100 | + n ? eta_str : "--:--:--"); | |
101 | } | |
102 | if (nn > bar->maxlen) | |
103 | bar->maxlen = nn; |