]> granicus.if.org Git - neomutt/commitdiff
feature: progress bar
authorStefan Kuhn <wuodan@hispeed.ch>
Sat, 30 Jan 2016 16:13:53 +0000 (16:13 +0000)
committerRichard Russon <rich@flatcap.org>
Mon, 4 Apr 2016 02:34:28 +0000 (03:34 +0100)
Show a visual progress bar on slow operations

color.c
curs_lib.c
doc/manual.xml.head
mutt_curses.h

diff --git a/color.c b/color.c
index 6e29603f74c09291d723058a05732bb06bdc8403..8ffba57d2c349a15cd5266dc134c115a7acb7d45 100644 (file)
--- a/color.c
+++ b/color.c
@@ -93,6 +93,7 @@ static const struct mapping_t Fields[] =
   { "bold",            MT_COLOR_BOLD },
   { "underline",       MT_COLOR_UNDERLINE },
   { "index",           MT_COLOR_INDEX },
+  { "progress",                MT_COLOR_PROGRESS },
   { "prompt",          MT_COLOR_PROMPT },
   { NULL,              0 }
 };
index 3178f22100ef32dd87d03226602e81513a5ae471..0f4da466a57ad72f9372b12558048cee9ef8c36f 100644 (file)
@@ -411,6 +411,52 @@ void mutt_progress_init (progress_t* progress, const char *msg,
   mutt_progress_update (progress, 0, 0);
 }
 
+static void message_bar (int percent, const char *fmt, ...)
+{
+  va_list ap;
+  char buf[STRING], buf2[STRING];
+  int w = percent * COLS / 100;
+  size_t l;
+
+  va_start (ap, fmt);
+  vsnprintf (buf, sizeof (buf), fmt, ap);
+  l = mutt_strwidth (buf);
+  va_end (ap);
+
+  mutt_format_string(buf2, sizeof (buf2),
+    0, COLS-2, FMT_LEFT, 0, buf, sizeof (buf), 0);
+
+  move (LINES - 1, 0);
+
+  if (l < w)
+  {
+    SETCOLOR(MT_COLOR_PROGRESS);
+    addstr (buf2);
+    w -= l;
+    while (w--)
+      addch(' ');
+    SETCOLOR(MT_COLOR_NORMAL);
+    clrtoeol ();
+    mutt_refresh();
+  }
+  else
+  {
+    size_t bw;
+    char ch;
+    int off = mutt_wstr_trunc (buf2, sizeof (buf2), w, &bw);
+
+    ch = buf2[off];
+    buf2[off] = 0;
+    SETCOLOR(MT_COLOR_PROGRESS);
+    addstr (buf2);
+    buf2[off] = ch;
+    SETCOLOR(MT_COLOR_NORMAL);
+    addstr (&buf2[off]);
+    clrtoeol ();
+    mutt_refresh();
+  }
+}
+
 void mutt_progress_update (progress_t* progress, long pos, int percent)
 {
   char posstr[SHORT_STRING];
@@ -461,16 +507,16 @@ void mutt_progress_update (progress_t* progress, long pos, int percent)
 
     if (progress->size > 0)
     {
-      mutt_message ("%s %s/%s (%d%%)", progress->msg, posstr, progress->sizestr,
-                   percent > 0 ? percent :
-                       (int) (100.0 * (double) progress->pos / progress->size));
+      message_bar (percent > 0 ? percent : (int) (100.0 * (double) progress->pos / progress->size),
+        "%s %s/%s (%d%%)", progress->msg, posstr, progress->sizestr,
+        percent > 0 ? percent : (int) (100.0 * (double) progress->pos / progress->size));
     }
     else
     {
       if (percent > 0)
-       mutt_message ("%s %s (%d%%)", progress->msg, posstr, percent);
+        message_bar (percent, "%s %s (%d%%)", progress->msg, posstr, percent);
       else
-       mutt_message ("%s %s", progress->msg, posstr);
+        mutt_message ("%s %s", progress->msg, posstr);
     }
   }
 
index b90908f001610306861479d3bc7440f848d5e17c..3368eda9e67615947fc7450880c1a7f63f2d6bb1 100644 (file)
@@ -2706,6 +2706,7 @@ patterns.
 <listitem><para>markers (the <quote>+</quote> markers at the beginning of wrapped lines in the pager)</para></listitem>
 <listitem><para>message (informational messages)</para></listitem>
 <listitem><para>normal</para></listitem>
+<listitem><para>progress (visual progress bar)</para></listitem>
 <listitem><para>prompt</para></listitem>
 <listitem><para>quoted (text matching <link linkend="quote-regexp">$quote_regexp</link> in the body of a message)</para></listitem>
 <listitem><para>quoted1, quoted2, ..., quoted<emphasis>N</emphasis> (higher levels of quoting)</para></listitem>
index 93d9aeaac216dee7c4a2e66facabacb60f3d1567..620e490ef22992ade380b7184d9d9830a42957fe 100644 (file)
@@ -124,6 +124,7 @@ enum
   MT_COLOR_UNDERLINE,
   MT_COLOR_INDEX,
   MT_COLOR_PROMPT,
+  MT_COLOR_PROGRESS,
   MT_COLOR_MAX
 };