Hello, As Gisle pointed out in the other thread, the progress implementation had a few flaws. I've mostly ironed them all out in this patch. This is a slightly enhanced version of the patch I sent on the other thread related to progress bar implementation.
In a gist, this patch: 1. Cleans up output in case of dot-style progress bar by not printing extra newlines when not needed 2. Ensures all the columns are perfectly aligned in all (?) cases 3. Makes the filename column fixed width. This makes a much better image when downloading multiple files in quiet mode. Please do test this patch and I welcome any and all comments on it. On Wed, Apr 30, 2014 at 9:39 PM, Giuseppe Scrivano <[email protected]>wrote: > Darshit Shah <[email protected]> writes: > > > No, I haven't tried porting this code into parallel-wget yet. We'd > > have to edit all the calls to fd_read_body() which I'm assuming have > > shifted by a large amount so we'll have to manually merge it. This set > > of patches is for master only. > > feel free to push your patch whenever you want :) > > Giuseppe > -- Thanking You, Darshit Shah
From 6d4158122cf6d6e04e4f6c96e0d309e7390cc71a Mon Sep 17 00:00:00 2001 From: Darshit Shah <[email protected]> Date: Thu, 1 May 2014 23:08:52 +0200 Subject: [PATCH] Aesthetic changes and bug fixes for progress bar --- src/ChangeLog | 10 ++++++++++ src/progress.c | 19 ++++++++++--------- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 96723dd..92942eb 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,13 @@ +2014-05-01 Darshit Shah <[email protected]> (tiny change) + + * progress.c (dot_finish): Do not print extra newlines when not in verbose + mode. (Purely aesthetic change) + (get_eta): Add extra space when eta is printed. + (create_image): Remove erroneous space from being added to progress bar when + filename > MAX_FILENAME_LEN + (create_image): Remove extra space before printed download speeds + Make the filename a fixed width column. + 2014-04-19 Darshit Shah <[email protected]> * log.h (log_options): Add new logging options, LOG_PROGRESS. All progress diff --git a/src/progress.c b/src/progress.c index b1d5095..02aad11 100644 --- a/src/progress.c +++ b/src/progress.c @@ -407,7 +407,7 @@ dot_finish (void *progress, double dltime) } print_row_stats (dp, dltime, true); - logputs (LOG_PROGRESS, "\n\n"); + logputs (LOG_VERBOSE, "\n\n"); log_set_flush (false); xfree (dp); @@ -823,7 +823,7 @@ get_eta (int *bcd) { /* TRANSLATORS: "ETA" is English-centric, but this must be short, ideally 3 chars. Abbreviate if necessary. */ - static const char eta_str[] = N_(" eta %s"); + static const char eta_str[] = N_(" eta %s"); static const char *eta_trans; static int bytes_cols_diff; if (eta_trans == NULL) @@ -875,7 +875,7 @@ get_eta (int *bcd) static void create_image (struct bar_progress *bp, double dl_total_time, bool done) { - const int MAX_FILENAME_LEN = bp->width / 3; + const int MAX_FILENAME_LEN = bp->width / 4; char *p = bp->buffer; wgint size = bp->initial_length + bp->count; @@ -887,7 +887,6 @@ create_image (struct bar_progress *bp, double dl_total_time, bool done) struct bar_progress_hist *hist = &bp->hist; int orig_filename_len = strlen (bp->f_download); - int filename_len = MIN (orig_filename_len, MAX_FILENAME_LEN); /* The progress bar should look like this: file xx% [=======> ] nn,nnn 12.34KB/s eta 36m 51s @@ -909,7 +908,7 @@ create_image (struct bar_progress *bp, double dl_total_time, bool done) "=====>..." - progress bar - the rest */ int dlbytes_size = 1 + MAX (size_grouped_len, 11); - int progress_size = bp->width - (filename_len + 1 + 4 + 2 + dlbytes_size + 8 + 14); + int progress_size = bp->width - (MAX_FILENAME_LEN + 1 + 4 + 2 + dlbytes_size + 8 + 14); /* The difference between the number of bytes used, and the number of columns used. */ @@ -920,8 +919,11 @@ create_image (struct bar_progress *bp, double dl_total_time, bool done) if (orig_filename_len <= MAX_FILENAME_LEN) { + int padding = MAX_FILENAME_LEN - orig_filename_len; sprintf (p, "%s ", bp->f_download); - p += filename_len + 1; + p += orig_filename_len + 1; + for (;padding;padding--) + *p++ = ' '; } else { @@ -931,7 +933,6 @@ create_image (struct bar_progress *bp, double dl_total_time, bool done) offset = ((int) bp->tick) % (orig_filename_len - MAX_FILENAME_LEN); else offset = 0; - *p++ = ' '; memcpy (p, bp->f_download + offset, MAX_FILENAME_LEN); p += MAX_FILENAME_LEN; *p++ = ' '; @@ -1037,12 +1038,12 @@ create_image (struct bar_progress *bp, double dl_total_time, bool done) wgint dlquant = hist->total_bytes + bp->recent_bytes; double dltime = hist->total_time + (dl_total_time - bp->recent_start); double dlspeed = calc_rate (dlquant, dltime, &units); - sprintf (p, " %4.*f%s", dlspeed >= 99.95 ? 0 : dlspeed >= 9.995 ? 1 : 2, + sprintf (p, "%4.*f%s", dlspeed >= 99.95 ? 0 : dlspeed >= 9.995 ? 1 : 2, dlspeed, !opt.report_bps ? short_units[units] : short_units_bits[units]); move_to_end (p); } else - APPEND_LITERAL (" --.-K/s"); + APPEND_LITERAL ("--.-KB/s"); if (!done) { -- 1.9.2
