# include <strings.h>
#endif /* HAVE_STRING_H */
#include <assert.h>
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif
#include "wget.h"
#include "progress.h"
long dltime = wtimer_elapsed (bp->timer);
bp->count += howmuch;
- if (bp->count + bp->initial_length > bp->total_length)
+ if (bp->total_length > 0
+ && bp->count + bp->initial_length > bp->total_length)
/* We could be downloading more than total_length, e.g. when the
server sends an incorrect Content-Length header. In that case,
adjust bp->total_length to the new reality, so that the code in
bar_finish (void *progress)
{
struct bar_progress *bp = progress;
+ long elapsed = wtimer_elapsed (bp->timer);
+
+ if (elapsed == 0)
+ /* If the download was faster than the granularity of the timer,
+ fake some output so that we don't get the ugly "----.--" rate
+ at the download finish. */
+ elapsed = 1;
- create_image (bp, wtimer_elapsed (bp->timer));
+ create_image (bp, elapsed);
display_image (bp->buffer);
logputs (LOG_VERBOSE, "\n\n");
Calculate its geometry:
"xxx% " - percentage - 5 chars
- "| ... | " - progress bar decorations - 3 chars
+ "| ... |" - progress bar decorations - 2 chars
"1012.56 K/s " - dl rate - 12 chars
"nnnn " - downloaded bytes - 11 chars
"ETA: xx:xx:xx" - ETA - 13 chars
"=====>..." - progress bar content - the rest
*/
- int progress_len = screen_width - (5 + 3 + 12 + 11 + 13);
+ int progress_len = screen_width - (5 + 2 + 12 + 11 + 13);
if (progress_len < 7)
progress_len = 0;
}
else
{
- strcpy (p, "----.-- K/s ");
+ strcpy (p, " --.-- K/s ");
p += 12;
}
/* "12376 " */
- sprintf (p, _("%ld "), size);
+ sprintf (p, "%ld ", size);
p += strlen (p);
/* "ETA: xx:xx:xx" */
}
static void
-bar_set_params (const char *ignored)
+bar_set_params (const char *params)
{
int sw;
- if (opt.lfilename
+ if ((opt.lfilename
#ifdef HAVE_ISATTY
- || !isatty (fileno (stderr))
+ || !isatty (fileno (stderr))
#else
- 1
+ 1
#endif
- )
+ )
+ && !(params != NULL
+ && 0 == strcmp (params, "force")))
{
- /* We're not printing to a TTY. Revert to the fallback
- display. */
+ /* We're not printing to a TTY, so revert to the fallback
+ display. #### We're recursively calling
+ set_progress_implementation here, which is slightly kludgy.
+ It would be nicer if that function could resolve this problem
+ itself. */
set_progress_implementation (NULL);
return;
}