progress bar: Allow display on stderr alongwith -o

This commit causes the --show-progress option to print the progress bar
to stderr even when a logfile was explicitly provided on the command
line. Such a combination allows a user to log the output of Wget while
simultaneously keeping track of the download status.
This commit is contained in:
Darshit Shah 2015-01-18 15:18:14 +05:30 committed by Tim Ruehsen
parent a7e9a05a89
commit 8705e27e20
7 changed files with 42 additions and 10 deletions

View File

@ -774,12 +774,15 @@ use @samp{--progress=bar:force:noscroll}.
Force wget to display the progress bar in any verbosity.
By default, wget only displays the progress bar in verbose mode. One may
however want wget to display the progress bar on screen in conjunction with
however, want wget to display the progress bar on screen in conjunction with
any other verbosity modes like @samp{--no-verbose} or @samp{--quiet}. This
is often a desired a property when invoking wget to download several small/large
files. In such a case, wget could simply be invoked with this parameter to get
a much cleaner output on the screen.
This option will also force the progress bar to be printed to @file{stderr} when
used alongside the @samp{--logfile} option.
@item -N
@itemx --timestamping
Turn on time-stamping. @xref{Time-Stamping}, for details.

View File

@ -104,6 +104,7 @@ CMD_DECLARE (cmd_spec_htmlify);
CMD_DECLARE (cmd_spec_mirror);
CMD_DECLARE (cmd_spec_prefer_family);
CMD_DECLARE (cmd_spec_progress);
CMD_DECLARE (cmd_spec_progressdisp);
CMD_DECLARE (cmd_spec_recursive);
CMD_DECLARE (cmd_spec_regex_type);
CMD_DECLARE (cmd_spec_restrict_file_names);
@ -275,7 +276,7 @@ static const struct {
#endif
{ "serverresponse", &opt.server_response, cmd_boolean },
{ "showalldnsentries", &opt.show_all_dns_entries, cmd_boolean },
{ "showprogress", &opt.show_progress, cmd_boolean },
{ "showprogress", &opt.show_progress, cmd_spec_progressdisp },
{ "spanhosts", &opt.spanhost, cmd_boolean },
{ "spider", &opt.spider, cmd_boolean },
{ "startpos", &opt.start_pos, cmd_bytes },
@ -434,7 +435,7 @@ defaults (void)
/* Use a negative value to mark the absence of --start-pos option */
opt.start_pos = -1;
opt.show_progress = false;
opt.show_progress = -1;
opt.noscroll = false;
}
@ -1572,6 +1573,22 @@ cmd_spec_useragent (const char *com, const char *val, void *place_ignored _GL_UN
return true;
}
/* The --show-progress option is not a cmd_boolean since we need to keep track
* of whether the user explicitly requested the option or not. -1 means
* uninitialized. */
static bool
cmd_spec_progressdisp (const char *com, const char *val, void *place _GL_UNUSED)
{
bool flag;
if (cmd_boolean (com, val, &flag))
{
opt.show_progress = flag;
return true;
}
return false;
}
/* The "verbose" option cannot be cmd_boolean because the variable is
not bool -- it's of type int (-1 means uninitialized because of
some random hackery for disallowing -q -v). */
@ -1583,6 +1600,7 @@ cmd_spec_verbose (const char *com, const char *val, void *place_ignored _GL_UNUS
if (cmd_boolean (com, val, &flag))
{
opt.verbose = flag;
opt.show_progress = -1;
return true;
}
return false;

View File

@ -310,6 +310,14 @@ get_log_fp (void)
return stderr;
}
static FILE *
get_progress_fp (void)
{
if (opt.show_progress == true)
return stderr;
return get_log_fp();
}
/* Returns the file descriptor for the secondary log file. This is
WARCLOGFP, except if called before log_init, in which case it
returns stderr. This is useful in case someone calls a logging
@ -345,8 +353,14 @@ logputs (enum log_options o, const char *s)
FILE *warcfp;
check_redirect_output ();
if ((fp = get_log_fp ()) == NULL)
if (o == LOG_PROGRESS)
fp = get_progress_fp ();
else
fp = get_log_fp ();
if (fp == NULL)
return;
warcfp = get_warc_log_fp ();
CHECK_VERBOSE (o);

View File

@ -1272,9 +1272,6 @@ main (int argc, char **argv)
if (opt.verbose == -1)
opt.verbose = !opt.quiet;
if (opt.verbose == 1)
opt.show_progress = true;
/* Sanity checks. */
if (opt.verbose && opt.quiet)
{

View File

@ -133,7 +133,7 @@ struct options
char **no_proxy;
char *base_href;
char *progress_type; /* progress indicator type. */
bool show_progress; /* Show only the progress bar */
int show_progress; /* Show only the progress bar */
bool noscroll; /* Don't scroll the filename in the progressbar */
char *proxy_user; /*oli*/
char *proxy_passwd;

View File

@ -1202,7 +1202,7 @@ bar_set_params (char *params)
} while ((param = strtok (NULL, ":")) != NULL);
}
if ((opt.lfilename
if (((opt.lfilename && opt.show_progress != 1)
#ifdef HAVE_ISATTY
/* The progress bar doesn't make sense if the output is not a
TTY -- when logging to file, it is better to review the

View File

@ -1812,7 +1812,7 @@ determine_screen_width (void)
int fd;
struct winsize wsz;
if (opt.lfilename != NULL)
if (opt.lfilename != NULL && opt.show_progress != 1)
return 0;
fd = fileno (stderr);