Hi Mutt developers,
I'd like to suggest a feature for Mutt: to make it possible to move the
status line to the window title.
Currently we have ts_status_format with which it is possible to control
the window title. And with the mutt_xtitle script, the status of the
index, pager and compose status lines can be copied to the window title
when that script is used in status_format, pager_format and
compose_format. It is however not possible to do this for the status
lines of the eight other modes (browser, attach, query, postpone, alias,
pgp, smime, mix). And it is also not possible to remove the status
lines when they display information that is already displayed in the
window title.
I'm not sure what would be the best way to implement that feature, but
it seems to me that the simplest possibility would be to introduce two
sub-features with two configuration variables: (1) "status_line_format",
with a default empty value, to which all status lines would be passed
when it is set (for example to "mutt_xtitle"), and (2) a boolean
variable "status_line_display", with a default value yes.
I implemented this myself, and attach the resulting patch. Comments
welcome!
Gregory
diff --git a/compose.c b/compose.c
index a7520516..40d6666d 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_draw_status_window (MuttStatusWindow, buf);
menu->redraw &= ~REDRAW_STATUS;
}
diff --git a/contrib/mutt_xtitle b/contrib/mutt_xtitle
index f9b8a23f..d05a8aee 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..1b57134e 100644
--- a/curs_lib.c
+++ b/curs_lib.c
@@ -775,6 +775,12 @@ 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 +1463,58 @@ void mutt_paddstr (int n, const char *s)
addch (' ');
}
+void mutt_draw_status_window (mutt_window_t *w, char *s)
+{
+ char command[512], dst[256]; pid_t pid; FILE *filter; int n, r;
+ if (ProcessStatusLine)
+ {
+ if (strlen (ProcessStatusLine) + strlen (s) > 500)
+ {
+ dprint(1, (debugfile, "process_status_line command and status line lengths too long\n"));
+ }
+ else
+ {
+ command[0] = 0; strcat(command, ProcessStatusLine);
+ strcat(command, " '"); strcat(command, s); strcat(command, "'");
+ if ((pid = mutt_create_filter(command, NULL, &filter, NULL)) != -1)
+ {
+ n = fread(dst, 1, sizeof (dst), filter);
+ safe_fclose (&filter);
+ r = mutt_wait_filter(pid);
+ if (r != 0)
+ dprint(1, (debugfile, "process_status_line command exited with code %d\n", r));
+ if (n > 0)
+ {
+ dst[n] = 0;
+ while ((n > 0) && (dst[n-1] == '\n' || dst[n-1] == '\r')) dst[--n] = 0;
+ s = dst;
+ }
+ else
+ {
+ dprint(1, (debugfile, "error reading from process_status_line: %s (errno=%d)\n", strerror(errno), errno));
+ }
+ }
+ else
+ {
+ dprint (1, (debugfile, "calling process_status_line failed\n"));
+ }
+ }
+ }
+ 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, 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..4e7d3469 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_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..519fe5b0 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_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..c01cc1ed 100644
--- a/mutt_curses.h
+++ b/mutt_curses.h
@@ -208,6 +208,8 @@ 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_draw_status_window (mutt_window_t *, char *);
+void mutt_draw_help_window (mutt_window_t *, char *);
static inline int mutt_window_wrap_cols(mutt_window_t *win, short wrap)
diff --git a/pager.c b/pager.c
index 4346b638..391789bf 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_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_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;