Hi Kevin,

Thank you very much for your answer and comments.


Sorry I didn't have a chance to respond until now.


No worries, my feature request was only 26 hours old!


I'm not convinced this would be a generally useful feature, though, and I don't like to add options that have a user-size of "one".


I know, but in fact I'm convinced it could be a killer feature. It's a first step to make Mutt useable as a "library" by other programs.

Perhaps a few words about what I want to do with that feature will convince you: I'd like to use Mutt inside Emacs, and with this feature Mutt's status line can be moved to Emacs's mode-line.

I'll let you guess what the next (and last) step is to reach that goal ;-)


The filter part of the function is *really* clunky.


In fact this wasn't my code, I copied and adapted a part of muttlib.c:mutt_FormatString(), thinking indeed that this code was clunky. I should have looked closer to other parts of the code, sorry. I attach an updated patch, which is indeed much cleaner. Now I think a common function should be defined in muttlib.c, used by both mutt_FormatString() and mutt_process_status_line().


Also, I didn't have time to look deeply at index_status_lines/pager_status_lines flow and OPTSTATUSONTOP. I *think* it will deal okay with a status line with 0 rows, but would want to test and make sure about that.


I tested this, and it works. But I'm new to Mutt however, so perhaps I didn't test it thoroughly enough.

Gregory
diff --git a/compose.c b/compose.c
index a7520516..5414c952 100644
--- a/compose.c
+++ b/compose.c
@@ -993,10 +993,7 @@ static void compose_menu_redraw (MUTTMENU *menu)
   if (menu->redraw & REDRAW_STATUS)
   {
     compose_status_line (buf, sizeof (buf), 0, MuttStatusWindow->cols, menu, NONULL(ComposeFormat));
-    mutt_window_move (MuttStatusWindow, 0, 0);
-    SETCOLOR (MT_COLOR_STATUS);
-    mutt_paddstr (MuttStatusWindow->cols, buf);
-    NORMAL_COLOR;
+    mutt_process_and_draw_status_window (MuttStatusWindow, buf);
     menu->redraw &= ~REDRAW_STATUS;
   }
 
diff --git a/contrib/mutt_xtitle b/contrib/mutt_xtitle
index f9b8a23f..e0c15378 100755
--- a/contrib/mutt_xtitle
+++ b/contrib/mutt_xtitle
@@ -2,8 +2,9 @@
 # Demonstration of format string pipes. Sets the xterm title and returns the
 # string unchanged.
 #
-# Example usage:
+# Example usages:
 # set status_format="mutt_xtitle '%r %f (%L) [Msgs:%?M?%M/?%m%?n? New:%n?%?d? Del:%d?%?F? Flag:%F?%?t? Tag:%t?%?p? Post:%p?%?b? Inc:%b?]'|"
+# set process_status_line=mutt_xtitle
 
-printf "\033]0;$1\007" > /dev/tty
+printf "\033]0;$(echo "$1" | sed 's/%/%%/g')\007" > /dev/tty
 echo "$1"
diff --git a/curs_lib.c b/curs_lib.c
index 01bcde69..8026337f 100644
--- a/curs_lib.c
+++ b/curs_lib.c
@@ -775,6 +775,13 @@ void mutt_reflow_windows (void)
   MuttMessageWindow->row_offset = LINES - 1;
 
   memcpy (MuttIndexWindow, MuttStatusWindow, sizeof (mutt_window_t));
+
+  if (! option (OPTDISPLAYSTATUSBAR))
+  {
+    MuttStatusWindow->rows = 0;
+    MuttStatusWindow->cols = 0;
+  }
+
   MuttIndexWindow->rows = MAX(LINES - MuttStatusWindow->rows -
 			      MuttHelpWindow->rows - MuttMessageWindow->rows, 0);
   MuttIndexWindow->row_offset = option (OPTSTATUSONTOP) ? MuttStatusWindow->rows :
@@ -1457,6 +1464,67 @@ void mutt_paddstr (int n, const char *s)
     addch (' ');
 }
 
+static char *mutt_process_status_line (char *s)
+{
+  BUFFER *command, *status; FILE *filter; char *ps = NULL; size_t ps_size; int r; pid_t pid;
+
+  if (!ProcessStatusLine)
+    return s;
+
+  status = mutt_buffer_new ();
+  mutt_buffer_quote_filename (status, s);
+
+  command = mutt_buffer_new ();
+  mutt_buffer_addstr (command, ProcessStatusLine);
+  mutt_buffer_addstr (command, " ");
+  mutt_buffer_addstr (command, status->data);
+
+  if ((pid = mutt_create_filter (command->data, NULL, &filter, NULL)) < 0)
+  {
+    dprint (1, (debugfile, "calling process_status_line command failed\n"));
+    goto cleanup;
+  }
+  ps = mutt_read_line (NULL, &ps_size, filter, NULL, 0);
+  safe_fclose (&filter);
+  r = mutt_wait_filter (pid);
+  if (ps != NULL && r == 0)
+    s = ps;
+  else
+    dprint (1, (debugfile, "process_status_line command failed\n"));
+
+ cleanup:
+  mutt_buffer_pool_release (&status);
+  mutt_buffer_pool_release (&command);
+  return s;
+}
+
+void mutt_process_and_draw_status_window (mutt_window_t *w, char *s)
+{
+  mutt_draw_status_window (w, mutt_process_status_line (s));
+}
+
+void mutt_draw_status_window (mutt_window_t *w, char *s)
+{
+  if (! option (OPTDISPLAYSTATUSBAR))
+    return;
+
+  SETCOLOR (MT_COLOR_STATUS);
+  mutt_window_move (w, 0, 0);
+  mutt_paddstr (w->cols, s);
+  NORMAL_COLOR;
+}
+
+void mutt_draw_help_window (mutt_window_t *w, const char *s)
+{
+  if (! option (OPTHELP))
+    return;
+
+  SETCOLOR (MT_COLOR_STATUS);
+  mutt_window_move (w, 0, 0);
+  mutt_paddstr (w->cols, s);
+  NORMAL_COLOR;
+}
+
 /* See how many bytes to copy from string so its at most maxlen bytes
  * long and maxwid columns wide */
 size_t mutt_wstr_trunc (const char *src, size_t maxlen, size_t maxwid, size_t *width)
diff --git a/curs_main.c b/curs_main.c
index 19427025..cf2f3153 100644
--- a/curs_main.c
+++ b/curs_main.c
@@ -592,10 +592,7 @@ static void index_menu_redraw (MUTTMENU *menu)
   if (menu->redraw & REDRAW_STATUS)
   {
     menu_status_line (buf, sizeof (buf), menu, NONULL (Status));
-    mutt_window_move (MuttStatusWindow, 0, 0);
-    SETCOLOR (MT_COLOR_STATUS);
-    mutt_paddstr (MuttStatusWindow->cols, buf);
-    NORMAL_COLOR;
+    mutt_process_and_draw_status_window (MuttStatusWindow, buf);
     menu->redraw &= ~REDRAW_STATUS;
     if (option(OPTTSENABLED) && TSSupported)
     {
diff --git a/globals.h b/globals.h
index a0a07af1..88284ca0 100644
--- a/globals.h
+++ b/globals.h
@@ -178,6 +178,7 @@ WHERE char *Visual;
 WHERE char *CurrentFolder;
 WHERE char *LastFolder;
 
+WHERE char *ProcessStatusLine;
 
 WHERE const char *ReleaseDate;
 
diff --git a/init.h b/init.h
index 31c2ae41..6491d634 100644
--- a/init.h
+++ b/init.h
@@ -4587,6 +4587,22 @@ struct option_t MuttVars[] = {
   ** Also see the $$read_inc, $$net_inc and $$time_inc variables and the
   ** ``$tuning'' section of the manual for performance considerations.
   */
+  { "display_status_bar", DT_BOOL, R_REFLOW, {.l=OPTDISPLAYSTATUSBAR}, {.l=1} },
+  /*
+  ** .pp
+  ** Unsetting this variable causes the ``status bar'' to be hidden.
+  ** This variable has however no effect on the status bar of the
+  ** mini-index that is displayed when pager_index_lines is non-zero.
+  ** .pp
+  */
+  { "process_status_line", DT_STR, R_NONE, {.p=&ProcessStatusLine}, {.p=0} },
+  /*
+  ** .pp
+  ** Setting this variable causes the status line (displayed in the
+  ** ``status bar'' if $$display_status_bar is set) to be passed to
+  ** that external script or program and replaced by its output.
+  ** .pp
+  */
   {"xterm_icon",	DT_SYN,  R_NONE, {.p="ts_icon_format"}, {.p=0} },
   /*
   */
diff --git a/menu.c b/menu.c
index a7fff292..0274a894 100644
--- a/menu.c
+++ b/menu.c
@@ -230,13 +230,7 @@ void menu_redraw_full (MUTTMENU *menu)
   move (0, 0);
   clrtobot ();
 
-  if (option (OPTHELP))
-  {
-    SETCOLOR (MT_COLOR_STATUS);
-    mutt_window_move (menu->helpwin, 0, 0);
-    mutt_paddstr (menu->helpwin->cols, menu->help);
-    NORMAL_COLOR;
-  }
+  mutt_draw_help_window (menu->helpwin, menu->help);
   menu->offset = 0;
   menu->pagelen = menu->indexwin->rows;
 
@@ -253,10 +247,7 @@ void menu_redraw_status (MUTTMENU *menu)
   char buf[STRING];
 
   snprintf (buf, sizeof (buf), MUTT_MODEFMT, menu->title);
-  SETCOLOR (MT_COLOR_STATUS);
-  mutt_window_move (menu->statuswin, 0, 0);
-  mutt_paddstr (menu->statuswin->cols, buf);
-  NORMAL_COLOR;
+  mutt_process_and_draw_status_window (menu->statuswin, buf);
   menu->redraw &= ~REDRAW_STATUS;
 }
 
diff --git a/mutt.h b/mutt.h
index 8f45e67f..29088759 100644
--- a/mutt.h
+++ b/mutt.h
@@ -570,6 +570,7 @@ enum
   OPTWRAPSEARCH,
   OPTWRITEBCC,		/* write out a bcc header? */
   OPTXMAILER,
+  OPTDISPLAYSTATUSBAR,
 
   OPTCRYPTUSEGPGME,
   OPTCRYPTUSEPKA,
diff --git a/mutt_curses.h b/mutt_curses.h
index f21e0eab..fe579acb 100644
--- a/mutt_curses.h
+++ b/mutt_curses.h
@@ -208,6 +208,9 @@ int mutt_window_mvprintw (mutt_window_t *, int row, int col, const char *fmt, ..
 void mutt_window_clrtoeol (mutt_window_t *);
 void mutt_window_clearline (mutt_window_t *, int row);
 void mutt_window_getyx (mutt_window_t *, int *y, int *x);
+void mutt_process_and_draw_status_window (mutt_window_t *, char *);
+void mutt_draw_status_window (mutt_window_t *, char *);
+void mutt_draw_help_window (mutt_window_t *, const char *);
 
 
 static inline int mutt_window_wrap_cols(mutt_window_t *win, short wrap)
diff --git a/pager.c b/pager.c
index 4346b638..cc8c824c 100644
--- a/pager.c
+++ b/pager.c
@@ -1706,13 +1706,7 @@ static void pager_menu_redraw (MUTTMENU *pager_menu)
       }
     }
 
-    if (option (OPTHELP))
-    {
-      SETCOLOR (MT_COLOR_STATUS);
-      mutt_window_move (MuttHelpWindow, 0, 0);
-      mutt_paddstr (MuttHelpWindow->cols, rd->helpstr);
-      NORMAL_COLOR;
-    }
+    mutt_draw_help_window (MuttHelpWindow, rd->helpstr);
 
 #if defined (USE_SLANG_CURSES) || defined (HAVE_RESIZETERM)
     if (Resize != NULL)
@@ -1877,24 +1871,20 @@ static void pager_menu_redraw (MUTTMENU *pager_menu)
       strfcpy(pager_progress_str, (rd->topline == 0) ? "all" : "end", sizeof(pager_progress_str));
 
     /* print out the pager status bar */
-    mutt_window_move (rd->pager_status_window, 0, 0);
-    SETCOLOR (MT_COLOR_STATUS);
-
     if (IsHeader (rd->extra) || IsMsgAttach (rd->extra))
     {
       size_t l1 = rd->pager_status_window->cols * MB_LEN_MAX;
       size_t l2 = sizeof (buffer);
       hfi.hdr = (IsHeader (rd->extra)) ? rd->extra->hdr : rd->extra->bdy->hdr;
       mutt_make_string_info (buffer, l1 < l2 ? l1 : l2, rd->pager_status_window->cols, NONULL (PagerFmt), &hfi, 0);
-      mutt_paddstr (rd->pager_status_window->cols, buffer);
+      mutt_process_and_draw_status_window (rd->pager_status_window, buffer);
     }
     else
     {
       char bn[STRING];
       snprintf (bn, sizeof (bn), "%s (%s)", rd->banner, pager_progress_str);
-      mutt_paddstr (rd->pager_status_window->cols, bn);
+      mutt_process_and_draw_status_window (rd->pager_status_window, bn);
     }
-    NORMAL_COLOR;
     if (option(OPTTSENABLED) && TSSupported)
     {
       menu_status_line (buffer, sizeof (buffer), rd->index, NONULL (TSStatusFormat));
@@ -1913,11 +1903,7 @@ static void pager_menu_redraw (MUTTMENU *pager_menu)
 
     /* print out the index status bar */
     menu_status_line (buffer, sizeof (buffer), rd->index, NONULL(Status));
-
-    mutt_window_move (rd->index_status_window, 0, 0);
-    SETCOLOR (MT_COLOR_STATUS);
-    mutt_paddstr (rd->index_status_window->cols, buffer);
-    NORMAL_COLOR;
+    mutt_draw_status_window (rd->index_status_window, buffer);
   }
 
   pager_menu->redraw = 0;

Reply via email to