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