]>
Commit | Line | Data |
---|---|---|
9c2791f6 | 1 | diff -r -u poldek-0.18.3/vfile/vfprogress.c poldek-0.18.3-patrys/vfile/vfprogress.c |
25e388c1 | 2 | --- poldek-0.18.3/vfile/vfprogress.c 2004-04-02 13:15:40.450672496 +0200 |
9c2791f6 | 3 | +++ poldek-0.18.3-patrys/vfile/vfprogress.c 2004-04-02 13:27:30.161780008 +0200 |
25e388c1 PZ |
4 | @@ -68,6 +68,7 @@ |
5 | time_t current_time; | |
6 | float transfer_rate = 0.0; | |
7 | float eta = 0.0; | |
8 | + int screen_width = term_get_width(); | |
9 | ||
10 | if (bar->state == VF_PROGRESS_DISABLED) | |
11 | return; | |
9c2791f6 | 12 | @@ -79,8 +80,19 @@ |
25e388c1 PZ |
13 | bar->state = VF_PROGRESS_DISABLED; |
14 | return; | |
15 | } | |
16 | + | |
17 | + if (screen_width < 50) /* what kind of terminal is this?! */ | |
18 | + { | |
19 | + screen_width = 50; | |
9c2791f6 PZ |
20 | + } |
21 | + if (screen_width > 255) /* this might cause problems */ | |
22 | + { | |
23 | + screen_width = 255; | |
25e388c1 PZ |
24 | + } |
25 | ||
26 | if (bar->state == VF_PROGRESS_VIRGIN) { | |
27 | + /* calling progress bar for the first time */ | |
28 | + bar->width = screen_width - 48; /* calculate bar width = screen width - 8 - unit_line*/ | |
29 | if (total > 0) { | |
30 | if (total == amount || /* downloaded before progress() call */ | |
31 | total < 1024) { /* too small to show to */ | |
9c2791f6 | 32 | @@ -113,9 +125,11 @@ |
40ed15cb PZ |
33 | return; |
34 | } | |
40ed15cb | 35 | |
3286be84 PZ |
36 | - n_assert(bar->prev_n < 100); |
37 | +// n_assert(bar->prev_n <= bar_width); /* not needed */ | |
40ed15cb PZ |
38 | |
39 | if (!bar->is_tty) { | |
25e388c1 PZ |
40 | + |
41 | + | |
42 | int k; | |
43 | ||
44 | k = n - bar->prev_n; | |
9c2791f6 | 45 | @@ -131,29 +145,32 @@ |
25e388c1 PZ |
46 | } |
47 | ||
48 | } else { | |
49 | - char unit_line[43], amount_str[16], total_str[16]; | |
50 | - int nn, unit_n; | |
51 | - | |
52 | + | |
53 | +// ........................................ 99.2% [999.9K of 999.9K] [999.9K/s] [999m00s] | |
54 | + | |
55 | + char unit_line[40], amount_str[16], total_str[16], transfer_str[16]; | |
56 | + int nn, unit_n; | |
57 | ||
58 | current_time = time(NULL); | |
59 | if (current_time != bar->time_base) | |
60 | { | |
61 | - transfer_rate = amount / (current_time - bar->time_base) / 1024.0; | |
62 | + transfer_rate = amount / (current_time - bar->time_base); | |
63 | } | |
64 | if (transfer_rate > 0) | |
65 | { | |
66 | - eta = 0.5 + (total - amount) / (transfer_rate * 1024); | |
67 | + eta = 0.5 + (total - amount) / (transfer_rate); | |
68 | } | |
69 | ||
70 | nbytes2str(total_str, sizeof(total_str), total); | |
71 | nbytes2str(amount_str, sizeof(amount_str), amount); | |
72 | + nbytes2str(transfer_str, sizeof(transfer_str), transfer_rate); | |
73 | ||
74 | if (total == amount) | |
75 | - nn = n_snprintf(unit_line, sizeof(unit_line), "[%s] [%.1fK/s]", | |
76 | - total_str, transfer_rate); | |
77 | + nn = n_snprintf(unit_line, sizeof(unit_line), "[%6s] [%6s/s]", | |
78 | + total_str, transfer_str); | |
79 | else | |
80 | - nn = n_snprintf(unit_line, sizeof(unit_line), "[%s of %s] [%.1fK/s] [%dm%s%ds]", | |
81 | - amount_str, total_str, transfer_rate, (int)eta / 60, | |
82 | + nn = n_snprintf(unit_line, sizeof(unit_line), "[%6s of %6s] [%6s/s] [%3dm%s%ds]", | |
83 | + amount_str, total_str, transfer_str, (int)eta / 60, | |
84 | ((int)eta % 60 < 10 ? "0" : ""), (int)eta % 60); | |
40ed15cb | 85 | |
25e388c1 | 86 | unit_n = sizeof(unit_line) - nn - 1; |