static void
print_download_speed (struct dot_progress *dp, wgint bytes, double dltime)
{
- logprintf (LOG_VERBOSE, " %s",
- retr_rate (bytes, dltime - dp->last_timer_value, 1));
+ logprintf (LOG_VERBOSE, " %7s",
+ retr_rate (bytes, dltime - dp->last_timer_value));
dp->last_timer_value = dltime;
}
int last_eta_value;
};
-static void create_image (struct bar_progress *, double);
+static void create_image (struct bar_progress *, double, bool);
static void display_image (char *);
static void *
logputs (LOG_VERBOSE, "\n");
- create_image (bp, 0);
+ create_image (bp, 0, false);
display_image (bp->buffer);
return bp;
/* Don't update more often than five times per second. */
return;
- create_image (bp, dltime);
+ create_image (bp, dltime, false);
display_image (bp->buffer);
bp->last_screen_update = dltime;
}
/* See bar_update() for explanation. */
bp->total_length = bp->initial_length + bp->count;
- create_image (bp, dltime);
+ create_image (bp, dltime, true);
display_image (bp->buffer);
logputs (LOG_VERBOSE, "\n\n");
#endif
}
-static const char *eta_to_human (int);
+static const char *eta_to_human_short (int);
#define APPEND_LITERAL(s) do { \
memcpy (p, s, sizeof (s) - 1); \
#endif
static void
-create_image (struct bar_progress *bp, double dl_total_time)
+create_image (struct bar_progress *bp, double dl_total_time, bool done)
{
char *p = bp->buffer;
wgint size = bp->initial_length + bp->count;
else
APPEND_LITERAL (" --.--K/s");
- /* " ETA ..m ..s"; 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 && bp->count > 0 && dl_total_time > 3000)
+ if (!done)
{
- int eta;
-
- /* Don't change the value of ETA more than approximately once
- per second; doing so would cause flashing without providing
- any value to the user. */
- if (bp->total_length != size
- && bp->last_eta_value != 0
- && dl_total_time - bp->last_eta_time < 900)
- eta = bp->last_eta_value;
- else
+ /* " eta ..m ..s"; 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 && bp->count > 0 && dl_total_time > 3000)
{
- /* Calculate ETA using the average download speed to predict
- the future speed. If you want to use a speed averaged
- over a more recent period, replace dl_total_time with
- hist->total_time and bp->count with hist->total_bytes.
- I found that doing that results in a very jerky and
- ultimately unreliable ETA. */
- double time_sofar = (double) dl_total_time / 1000;
- wgint bytes_remaining = bp->total_length - size;
- eta = (int) (time_sofar * bytes_remaining / bp->count + 0.5);
- bp->last_eta_value = eta;
- bp->last_eta_time = dl_total_time;
+ int eta;
+
+ /* Don't change the value of ETA more than approximately once
+ per second; doing so would cause flashing without providing
+ any value to the user. */
+ if (bp->total_length != size
+ && bp->last_eta_value != 0
+ && dl_total_time - bp->last_eta_time < 900)
+ eta = bp->last_eta_value;
+ else
+ {
+ /* Calculate ETA using the average download speed to predict
+ the future speed. If you want to use a speed averaged
+ over a more recent period, replace dl_total_time with
+ hist->total_time and bp->count with hist->total_bytes.
+ I found that doing that results in a very jerky and
+ ultimately unreliable ETA. */
+ double time_sofar = (double) dl_total_time / 1000;
+ wgint bytes_remaining = bp->total_length - size;
+ eta = (int) (time_sofar * bytes_remaining / bp->count + 0.5);
+ bp->last_eta_value = eta;
+ bp->last_eta_time = dl_total_time;
+ }
+
+ sprintf (p, " eta %s", eta_to_human_short (eta));
+ p += strlen (p);
+ }
+ else if (bp->total_length > 0)
+ {
+ APPEND_LITERAL (" ");
}
-
- sprintf (p, " eta %s", eta_to_human (eta));
- p += strlen (p);
}
- else if (bp->total_length > 0)
+ else
{
- APPEND_LITERAL (" ");
+ /* When the download is done, print the elapsed time. */
+ sprintf (p, _(" in %s"), eta_to_human_short (dl_total_time / 1000 + 0.5));
+ p += strlen (p);
}
assert (p - bp->buffer <= bp->width);
}
#endif
-/* Provide a human-readable rendition of the ETA. It never occupies
- more than 7 characters of screen space. */
+/* Provide a short human-readable rendition of the ETA. It never
+ occupies more than 7 characters of screen space. */
static const char *
-eta_to_human (int secs)
+eta_to_human_short (int secs)
{
static char buf[10]; /* 8 is enough, but just in case */
static int last = -1;
last = secs;
if (secs < 100)
- sprintf (buf, "%ds", secs);
+ sprintf (buf, _("%ds"), secs);
else if (secs < 100 * 60)
- sprintf (buf, "%dm %ds", secs / 60, secs % 60);
+ sprintf (buf, _("%dm %ds"), secs / 60, secs % 60);
else if (secs < 100 * 3600)
- sprintf (buf, "%dh %dm", secs / 3600, (secs / 60) % 60);
+ sprintf (buf, _("%dh %dm"), secs / 3600, (secs / 60) % 60);
else if (secs < 100 * 86400)
- sprintf (buf, "%dd %dh", secs / 86400, (secs / 3600) % 60);
+ sprintf (buf, _("%dd %dh"), secs / 86400, (secs / 3600) % 60);
else
/* (2^31-1)/86400 doesn't overflow BUF. */
- sprintf (buf, "%dd", secs / 86400);
+ sprintf (buf, _("%dd"), secs / 86400);
return buf;
}