1
0
mirror of https://github.com/moparisthebest/wget synced 2024-07-03 16:38:41 -04:00

[svn] Indicate where the download has started in progress bar.

This commit is contained in:
hniksic 2003-09-22 10:14:19 -07:00
parent c2ffc02ab3
commit 625a9d3a9f
2 changed files with 33 additions and 18 deletions

View File

@ -1,5 +1,9 @@
2003-09-22 Hrvoje Niksic <hniksic@xemacs.org> 2003-09-22 Hrvoje Niksic <hniksic@xemacs.org>
* progress.c (create_image): Print the initial part of the
download with '-' characters, analogous to how dot progress prints
the initial part with ','.
* hash.c (ptrhash): New function. * hash.c (ptrhash): New function.
(ptrcmp): Ditto. (ptrcmp): Ditto.
(hash_table_new): Default to identity hash table. (hash_table_new): Default to identity hash table.

View File

@ -414,13 +414,13 @@ dot_set_params (const char *params)
static int screen_width = DEFAULT_SCREEN_WIDTH; static int screen_width = DEFAULT_SCREEN_WIDTH;
/* Size of the download speed history ring. */ /* Size of the download speed history ring. */
#define DLSPEED_HISTORY_SIZE 30 #define DLSPEED_HISTORY_SIZE 20
/* The minimum time length of a history sample. By default, each /* The minimum time length of a history sample. By default, each
sample is at least 100ms long, which means that, over the course of sample is at least 150ms long, which means that, over the course of
30 samples, "current" download speed spans at least 3s into the 20 samples, "current" download speed spans at least 3s into the
past. */ past. */
#define DLSPEED_SAMPLE_MIN 100 #define DLSPEED_SAMPLE_MIN 150
struct bar_progress { struct bar_progress {
long initial_length; /* how many bytes have been downloaded long initial_length; /* how many bytes have been downloaded
@ -561,19 +561,19 @@ bar_finish (void *progress, double dltime)
speed, over the course of no less than 3s. (Shorter intervals speed, over the course of no less than 3s. (Shorter intervals
produce very erratic results.) produce very erratic results.)
To do so, it samples the speed in 0.1s intervals and stores the To do so, it samples the speed in 150ms intervals and stores the
recorded samples in a FIFO history ring. The ring stores no more recorded samples in a FIFO history ring. The ring stores no more
than 30 intervals, hence the history covers the period of at least than 20 intervals, hence the history covers the period of at least
three seconds and at most 30 reads into the past. This method three seconds and at most 20 reads into the past. This method
should produce good results for both very fast and very slow should produce reasonable results for downloads ranging from very
downloads. slow to very fast.
The idea is that for fast downloads, we get the speed over exactly The idea is that for fast downloads, we get the speed over exactly
the last three seconds. For slow downloads (where a network read the last three seconds. For slow downloads (where a network read
takes more than 0.1s to complete), we get the speed over a larger takes more than 150ms to complete), we get the speed over a larger
time period, as large as it takes to complete thirty reads. This time period, as large as it takes to complete thirty reads. This
is good because slow downloads tend to fluctuate more and a is good because slow downloads tend to fluctuate more and a
3-second average would be very erratic. */ 3-second average would be too erratic. */
static void static void
update_speed_ring (struct bar_progress *bp, long howmuch, double dltime) update_speed_ring (struct bar_progress *bp, long howmuch, double dltime)
@ -688,29 +688,38 @@ create_image (struct bar_progress *bp, double dl_total_time)
else else
APPEND_LITERAL (" "); APPEND_LITERAL (" ");
/* The progress bar: "[====> ]" */ /* The progress bar: "[====> ]" or "[--==> ]". */
if (progress_size && bp->total_length > 0) if (progress_size && bp->total_length > 0)
{ {
double fraction = (double)size / bp->total_length; /* Size of the initial portion. */
int dlsz = (int)(fraction * progress_size); int insz = (double)bp->initial_length / bp->total_length * progress_size;
/* Size of the downloaded portion. */
int dlsz = (double)size / bp->total_length * progress_size;
char *begin; char *begin;
int i;
assert (dlsz <= progress_size); assert (dlsz <= progress_size);
assert (insz <= dlsz);
*p++ = '['; *p++ = '[';
begin = p; begin = p;
/* Print the initial portion of the download with '-' chars, the
rest with '=' and one '>'. */
for (i = 0; i < insz; i++)
*p++ = '-';
dlsz -= insz;
if (dlsz > 0) if (dlsz > 0)
{ {
/* Draw dlsz-1 '=' chars and one arrow char. */ for (i = 0; i < dlsz - 1; i++)
while (dlsz-- > 1)
*p++ = '='; *p++ = '=';
*p++ = '>'; *p++ = '>';
} }
while (p - begin < progress_size) while (p - begin < progress_size)
*p++ = ' '; *p++ = ' ';
*p++ = ']'; *p++ = ']';
} }
else if (progress_size) else if (progress_size)
@ -758,7 +767,9 @@ create_image (struct bar_progress *bp, double dl_total_time)
else else
APPEND_LITERAL (" --.--K/s"); APPEND_LITERAL (" --.--K/s");
/* " ETA xx:xx:xx" */ /* " ETA xx:xx:xx"; wait for three seconds before displaying the ETA.
That's because the ETA value needs a while to become
reliable. */
if (bp->total_length > 0 && dl_total_time > 3000) if (bp->total_length > 0 && dl_total_time > 3000)
{ {
long eta; long eta;