<<< Date Index >>>     <<< Thread Index >>>

[PATCH] Colored progress bar



Hi,

since I've asked several times for the patch, here we go. It adds a
"progress" color item that draws a vertical progress bar in the last
line. I find this easier to watch with just one eye for long operations
than to scan percentages printed by mutt.

Rocco
comparing with ../pdmef/progress
searching for changes
diff --git a/PATCHES b/PATCHES
--- a/PATCHES
+++ b/PATCHES
@@ -0,0 +1,1 @@
+patch-1.5.17hg.pdmef.progress.1
diff --git a/color.c b/color.c
--- a/color.c
+++ b/color.c
@@ -93,6 +93,7 @@ static struct mapping_t Fields[] =
   { "bold",            MT_COLOR_BOLD },
   { "underline",       MT_COLOR_UNDERLINE },
   { "index",           MT_COLOR_INDEX },
+  { "progress",         MT_COLOR_PROGRESS },
   { NULL,              0 }
 };
 
diff --git a/curs_lib.c b/curs_lib.c
--- a/curs_lib.c
+++ b/curs_lib.c
@@ -386,6 +386,52 @@ void mutt_progress_init (progress_t* pro
   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[w]);
+    clrtoeol ();
+    mutt_refresh();
+  }
+}
+
 void mutt_progress_update (progress_t* progress, long pos, int percent)
 {
   char posstr[SHORT_STRING];
@@ -435,14 +481,14 @@ void mutt_progress_update (progress_t* p
 
     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);
     }
diff --git a/doc/manual.xml.head b/doc/manual.xml.head
--- a/doc/manual.xml.head
+++ b/doc/manual.xml.head
@@ -2338,6 +2338,7 @@ in the header/body of a message, <emphas
 <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>quoted (text matching <link 
linkend="quote-regexp">&dollar;quote&lowbar;regexp</link> in the body of a 
message)</para></listitem>
 <listitem><para>quoted1, quoted2, ..., quoted<emphasis 
role="bold">N</emphasis> (higher levels of quoting)</para></listitem>
 <listitem><para>search (hiliting of words in the pager)</para></listitem>
diff --git a/mutt_curses.h b/mutt_curses.h
--- a/mutt_curses.h
+++ b/mutt_curses.h
@@ -126,6 +126,7 @@ enum
   MT_COLOR_BOLD,
   MT_COLOR_UNDERLINE,
   MT_COLOR_INDEX,
+  MT_COLOR_PROGRESS,
   MT_COLOR_MAX
 };