X-Git-Url: http://sjero.net/git/?p=wget;a=blobdiff_plain;f=src%2Fprogress.c;h=0c809eb1ee2c182fdedbed9eb5cbe352132bf65d;hp=b1d509504c3889ea991ce4432273eeb5ecc6efad;hb=HEAD;hpb=8c2fd06ba80b5312b4540859d452664450ec054f diff --git a/src/progress.c b/src/progress.c index b1d50950..0c809eb1 100644 --- a/src/progress.c +++ b/src/progress.c @@ -51,7 +51,7 @@ struct progress_implementation { void (*update) (void *, wgint, double); void (*draw) (void *); void (*finish) (void *, double); - void (*set_params) (const char *); + void (*set_params) (char *); }; /* Necessary forward declarations. */ @@ -60,13 +60,13 @@ static void *dot_create (const char *, wgint, wgint); static void dot_update (void *, wgint, double); static void dot_finish (void *, double); static void dot_draw (void *); -static void dot_set_params (const char *); +static void dot_set_params (char *); static void *bar_create (const char *, wgint, wgint); static void bar_update (void *, wgint, double); static void bar_draw (void *); static void bar_finish (void *, double); -static void bar_set_params (const char *); +static void bar_set_params (char *); static struct progress_implementation implementations[] = { { "dot", 0, dot_create, dot_update, dot_draw, dot_finish, dot_set_params }, @@ -112,7 +112,7 @@ set_progress_implementation (const char *name) { size_t i, namelen; struct progress_implementation *pi = implementations; - const char *colon; + char *colon; if (!name) name = DEFAULT_PROGRESS_IMPLEMENTATION; @@ -173,7 +173,7 @@ progress_create (const char *f_download, wgint initial, wgint total) and current update. */ bool -progress_interactive_p (void *progress) +progress_interactive_p (void *progress _GL_UNUSED) { return current_impl->interactive; } @@ -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); @@ -419,7 +419,7 @@ dot_finish (void *progress, double dltime) giga. */ static void -dot_set_params (const char *params) +dot_set_params (char *params) { if (!params || !*params) params = opt.dot_style; @@ -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,10 +887,9 @@ 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 + file xx% [=======> ] nnn.nnK 12.34KB/s eta 36m 51s Calculate the geometry. The idea is to assign as much room as possible to the progress bar. The other idea is to never let @@ -899,17 +898,26 @@ create_image (struct bar_progress *bp, double dl_total_time, bool done) It would be especially bad for the progress bar to be resized randomly. - "file " - Downloaded filename - MAX MAX_FILENAME_LEN chars + 1 + "file " - Downloaded filename - MAX_FILENAME_LEN chars + 1 "xx% " or "100%" - percentage - 4 chars "[]" - progress bar decorations - 2 chars - " nnn,nnn,nnn" - downloaded bytes - 12 chars or very rarely more - " 12.5KB/s" - download rate - 9 chars + " nnn.nnK" - downloaded bytes - 7 chars + 1 + " 12.5KB/s" - download rate - 8 chars + 1 " eta 36m 51s" - ETA - 14 chars "=====>..." - 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); + +#define PROGRESS_FILENAME_LEN MAX_FILENAME_LEN + 1 +#define PROGRESS_PERCENT_LEN 4 +#define PROGRESS_DECORAT_LEN 2 +#define PROGRESS_FILESIZE_LEN 7 + 1 +#define PROGRESS_DWNLOAD_RATE 8 + 1 +#define PROGRESS_ETA_LEN 14 + + int progress_size = bp->width - (PROGRESS_FILENAME_LEN + PROGRESS_PERCENT_LEN + + PROGRESS_DECORAT_LEN + PROGRESS_FILESIZE_LEN + + PROGRESS_DWNLOAD_RATE + PROGRESS_ETA_LEN); /* The difference between the number of bytes used, and the number of columns used. */ @@ -920,18 +928,20 @@ 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 { int offset; - if (orig_filename_len > MAX_FILENAME_LEN) + if (((orig_filename_len > MAX_FILENAME_LEN) && !opt.noscroll) && !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++ = ' '; @@ -1013,13 +1023,20 @@ create_image (struct bar_progress *bp, double dl_total_time, bool done) } ++bp->tick; - /* " 234,567,890" */ - sprintf (p, " %s", size_grouped); + /* " 234.56M" */ + const char * down_size = human_readable (size, 1000, 2); + int cols_diff = 7 - count_cols (down_size); + while (cols_diff > 0) + { + *p++=' '; + cols_diff--; + } + sprintf (p, " %s", down_size); move_to_end (p); - /* Pad with spaces to 11 chars for the size_grouped field; + /* Pad with spaces to 7 chars for the size_grouped field; * couldn't use the field width specifier in sprintf, because * it counts in bytes, not characters. */ - for (size_grouped_pad = 11 - size_grouped_len; + for (size_grouped_pad = PROGRESS_FILESIZE_LEN - 7; size_grouped_pad > 0; --size_grouped_pad) { @@ -1029,8 +1046,8 @@ create_image (struct bar_progress *bp, double dl_total_time, bool done) /* " 12.52Kb/s or 12.52KB/s" */ if (hist->total_time > 0 && hist->total_bytes) { - static const char *short_units[] = { "B/s", "KB/s", "MB/s", "GB/s" }; - static const char *short_units_bits[] = { "b/s", "Kb/s", "Mb/s", "Gb/s" }; + static const char *short_units[] = { " B/s", "KB/s", "MB/s", "GB/s" }; + static const char *short_units_bits[] = { " b/s", "Kb/s", "Mb/s", "Gb/s" }; int units = 0; /* Calculate the download speed using the history ring and recent data that hasn't made it to the ring yet. */ @@ -1042,7 +1059,7 @@ create_image (struct bar_progress *bp, double dl_total_time, bool done) move_to_end (p); } else - APPEND_LITERAL (" --.-K/s"); + APPEND_LITERAL (" --.-KB/s"); if (!done) { @@ -1125,13 +1142,21 @@ display_image (char *buf) } static void -bar_set_params (const char *params) +bar_set_params (char *params) { char *term = getenv ("TERM"); - if (params - && 0 == strcmp (params, "force")) - current_impl_locked = 1; + if (params) + { + char *param = strtok (params, ":"); + do + { + if (0 == strcmp (param, "force")) + current_impl_locked = 1; + else if (0 == strcmp (param, "noscroll")) + opt.noscroll = true; + } while ((param = strtok (NULL, ":")) != NULL); + } if ((opt.lfilename #ifdef HAVE_ISATTY @@ -1161,7 +1186,7 @@ bar_set_params (const char *params) #ifdef SIGWINCH void -progress_handle_sigwinch (int sig) +progress_handle_sigwinch (int sig _GL_UNUSED) { received_sigwinch = 1; signal (SIGWINCH, progress_handle_sigwinch);