This patch causes --show-progress to display the progress bar to the
screen even when the --logfile option is provided to Wget.

If the --show-progress option is not explicitly enabled, then the old
behavior of printing the DOT progress to the log file is followed.
Do review the patch, and if no one has objections I'll push this in a few days

-- 
Thanking You,
Darshit Shah
From 58dad2a61ea370e99b596c1d361ce8735d10b6ab Mon Sep 17 00:00:00 2001
From: Darshit Shah <[email protected]>
Date: Sun, 18 Jan 2015 15:18:14 +0530
Subject: [PATCH] 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.
---
 doc/wget.texi  |  5 ++++-
 src/init.c     | 22 ++++++++++++++++++++--
 src/log.c      | 16 +++++++++++++++-
 src/main.c     |  3 ---
 src/options.h  |  2 +-
 src/progress.c |  2 +-
 src/utils.c    |  2 +-
 7 files changed, 42 insertions(+), 10 deletions(-)

diff --git a/doc/wget.texi b/doc/wget.texi
index d9ed17d..dafd7bb 100644
--- a/doc/wget.texi
+++ b/doc/wget.texi
@@ -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.
diff --git a/src/init.c b/src/init.c
index 569b25b..8c035df 100644
--- a/src/init.c
+++ b/src/init.c
@@ -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;
diff --git a/src/log.c b/src/log.c
index 72f91ba..654f440 100644
--- a/src/log.c
+++ b/src/log.c
@@ -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);
 
diff --git a/src/main.c b/src/main.c
index 6feb140..7675455 100644
--- a/src/main.c
+++ b/src/main.c
@@ -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)
     {
diff --git a/src/options.h b/src/options.h
index b995126..ffb04a9 100644
--- a/src/options.h
+++ b/src/options.h
@@ -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;
diff --git a/src/progress.c b/src/progress.c
index 132a8e5..92749c4 100644
--- a/src/progress.c
+++ b/src/progress.c
@@ -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
diff --git a/src/utils.c b/src/utils.c
index 0565666..3cc7d97 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -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);
-- 
2.2.2

Reply via email to