Date: Mon, 23 Aug 2004 19:04:19 +0200 From: Thomas Glanzmann To: Mutt Users Cc: Mutt Developers Subject: [PATCH] make it possible to colorize the status bar [WAS: Re: Remind me of postponed eMails in my status line while I am in index] Mail-Followup-To: Mutt Users , Mutt Developers In-Reply-To: <20040712170932.GK3476@cip.informatik.uni-erlangen.de> Hello together, * Thomas Glanzmann [040712 19:10]: > I am looking for a way to indicate postponed eMails in my status bar > preferable in red and CAPS lock POSTPONED. Any ways? I wrote an ugly patch which makes it possible to colorize the status bar (*index only* at the moment). Here[1] is the patch. And a screenshot is here[2]. To interprete the screenshot right: This is mutt running inside a screen with a caption (so the bottom line is from screen, not mutt). To use apply the patch to cvs HEAD and recompile. No additional configure, prepare is necessary. The patch comes at the moment without any documentation. If you have deltas please provide them as *delta* to *my patch* so that it is easy for me to merge the stuff into my bitkeeper tree. I renamed status to stdefault so ... color status foreground background becomes: color stdefault foreground background To use the new additional colorization use the following as example: color status brightred white Post:[0-9]+ color status brightred white Del:[0-9]+ color status brightred white New:[0-9]+ As usual please provide feedback. Honestly, Thomas [who just wrote another patch that will never make it into upstream] [1] http://wwwcip.informatik.uni-erlangen.de/~sithglan/mutt/patch-HEAD.tg.cstatus.0 [2] http://wwwcip.informatik.uni-erlangen.de/~sithglan/mutt/mutt-color-status.png diff -Nru a/color.c b/color.c --- a/color.c 2004-07-24 12:27:18 +02:00 +++ b/color.c 2004-08-23 12:10:04 +02:00 @@ -30,6 +30,7 @@ int ColorDefs[MT_COLOR_MAX]; COLOR_LINE *ColorHdrList = NULL; COLOR_LINE *ColorBodyList = NULL; +COLOR_LINE *ColorStatusList = NULL; COLOR_LINE *ColorIndexList = NULL; /* local to this file */ @@ -75,7 +76,7 @@ { "quoted", MT_COLOR_QUOTED }, { "signature", MT_COLOR_SIGNATURE }, { "indicator", MT_COLOR_INDICATOR }, - { "status", MT_COLOR_STATUS }, + { "stdefault", MT_COLOR_STDEFAULT }, { "tree", MT_COLOR_TREE }, { "error", MT_COLOR_ERROR }, { "normal", MT_COLOR_NORMAL }, @@ -89,6 +90,7 @@ { "bold", MT_COLOR_BOLD }, { "underline", MT_COLOR_UNDERLINE }, { "index", MT_COLOR_INDEX }, + { "status", MT_COLOR_STATUS }, { NULL, 0 } }; @@ -137,7 +139,7 @@ ColorQuoteUsed = 0; /* set some defaults */ - ColorDefs[MT_COLOR_STATUS] = A_REVERSE; + ColorDefs[MT_COLOR_STDEFAULT] = A_REVERSE; ColorDefs[MT_COLOR_INDICATOR] = A_REVERSE; ColorDefs[MT_COLOR_SEARCH] = A_REVERSE; ColorDefs[MT_COLOR_MARKERS] = A_REVERSE; @@ -689,7 +691,7 @@ /* extract a regular expression if needed */ - if (object == MT_COLOR_HEADER || object == MT_COLOR_BODY || object == MT_COLOR_INDEX) + if (object == MT_COLOR_HEADER || object == MT_COLOR_BODY || object == MT_COLOR_INDEX || object == MT_COLOR_STATUS) { if (!MoreArgs (s)) { @@ -728,6 +730,8 @@ r = add_pattern (&ColorHdrList, buf->data, 0, fg, bg, attr, err,0); else if (object == MT_COLOR_BODY) r = add_pattern (&ColorBodyList, buf->data, 1, fg, bg, attr, err, 0); + else if (object == MT_COLOR_STATUS) + r = add_pattern (&ColorStatusList, buf->data, 1, fg, bg, attr, err, 0); else if (object == MT_COLOR_INDEX) { r = add_pattern (&ColorIndexList, buf->data, 1, fg, bg, attr, err, 1); diff -Nru a/compose.c b/compose.c --- a/compose.c 2004-08-17 01:34:22 +02:00 +++ b/compose.c 2004-08-23 10:05:46 +02:00 @@ -263,9 +263,9 @@ redraw_mix_line (msg->chain); #endif - SETCOLOR (MT_COLOR_STATUS); + SETCOLOR (MT_COLOR_STDEFAULT); mvaddstr (HDR_ATTACH - 1, 0, _("-- Attachments")); - BKGDSET (MT_COLOR_STATUS); + BKGDSET (MT_COLOR_STDEFAULT); clrtoeol (); BKGDSET (MT_COLOR_NORMAL); @@ -1232,7 +1232,7 @@ { compose_status_line (buf, sizeof (buf), menu, NONULL(ComposeFormat)); CLEARLINE (option (OPTSTATUSONTOP) ? 0 : LINES-2); - SETCOLOR (MT_COLOR_STATUS); + SETCOLOR (MT_COLOR_STDEFAULT); printw ("%-*.*s", COLS, COLS, buf); SETCOLOR (MT_COLOR_NORMAL); menu->redraw &= ~REDRAW_STATUS; diff -Nru a/curs_main.c b/curs_main.c --- a/curs_main.c 2004-07-24 12:27:19 +02:00 +++ b/curs_main.c 2004-08-23 16:18:33 +02:00 @@ -393,6 +393,114 @@ menu->redraw = REDRAW_INDEX | REDRAW_STATUS; } +static void +draw_statusline(char *buf) +{ + int i = 0; + int cnt = 0; + int last_color = 0; + int color = 0; + int offset = 0; + int found = 0; + int null_rx = 0; + + + struct line_t { + short chunks; + struct syntax_t { + int color; + int first; + int last; + } *syntax; + } lineInfo = { 0, 0 }; + + + lineInfo.syntax = safe_malloc(sizeof(struct syntax_t)); + lineInfo.syntax[0].first = -1; + lineInfo.syntax[0].last = -1; + lineInfo.syntax[0].color = ColorDefs[MT_COLOR_STDEFAULT]; + lineInfo.chunks = 1; + + do + { + found = 0; + null_rx = 0; + regmatch_t pmatch[1], smatch[1]; + COLOR_LINE *color_line = ColorStatusList; + + if (!buf[offset]) + break; + + while (color_line) + { + if (regexec (&color_line->rx, buf + offset, 1, pmatch, + (offset ? REG_NOTBOL : 0)) == 0) + { + if (pmatch[0].rm_eo != pmatch[0].rm_so) + { + if (!found) + { + if (++(lineInfo.chunks) > 1) + safe_realloc (&(lineInfo.syntax), + (lineInfo.chunks) * sizeof (struct syntax_t)); + } + i = lineInfo.chunks - 1; + pmatch[0].rm_so += offset; + pmatch[0].rm_eo += offset; + if (!found || + pmatch[0].rm_so < (lineInfo.syntax)[i].first || + (pmatch[0].rm_so == (lineInfo.syntax)[i].first && + pmatch[0].rm_eo > (lineInfo.syntax)[i].last)) + { + (lineInfo.syntax)[i].color = color_line->pair; + (lineInfo.syntax)[i].first = pmatch[0].rm_so; + (lineInfo.syntax)[i].last = pmatch[0].rm_eo; + } + found = 1; + null_rx = 0; + } + else + null_rx = 1; /* empty regexp; don't add it, but keep looking */ + } + color_line = color_line->next; + } + + if (null_rx) + offset++; /* avoid degenerate cases */ + else + offset = (lineInfo.syntax)[i].last; + } while (found || null_rx); + + for (cnt = 0; cnt < mutt_strlen(buf); cnt++) { + color = lineInfo.syntax[0].color; + for (i = 0; i < lineInfo.chunks; i++) { + /* we assume the chunks are sorted */ + if (cnt > (lineInfo.syntax)[i].last) + continue; + if (cnt < (lineInfo.syntax)[i].first) + break; + if (cnt != (lineInfo.syntax)[i].last) { + color = (lineInfo.syntax)[i].color; + break; + } + /* don't break here, as cnt might be + * in the next chunk as well */ + } + if (color != last_color) { + attrset (color); + last_color = color; + } + addch (buf[cnt]); /* XXX more than one char at a time? */ +#if 0 + waddnstr(stdscr, tgbuf, 10); + SETCOLOR (MT_COLOR_NORMAL); + waddnstr(stdscr, tgbuf + 10, -1); +#endif + } + + safe_free(&lineInfo.syntax); +} + struct mapping_t IndexHelp[] = { { N_("Quit"), OP_QUIT }, { N_("Del"), OP_DELETE }, @@ -556,10 +664,17 @@ if (menu->redraw & REDRAW_STATUS) { + unsigned char tgbuf[2048]; + menu_status_line (buf, sizeof (buf), menu, NONULL (Status)); CLEARLINE (option (OPTSTATUSONTOP) ? 0 : LINES-2); - SETCOLOR (MT_COLOR_STATUS); + SETCOLOR (MT_COLOR_STDEFAULT); +#if 0 mutt_paddstr (COLS, buf); +#else + mutt_format_string(tgbuf, 2048, COLS, COLS, 0, ' ', buf, mutt_strlen(buf), 0); + draw_statusline(tgbuf); +#endif SETCOLOR (MT_COLOR_NORMAL); menu->redraw &= ~REDRAW_STATUS; } diff -Nru a/menu.c b/menu.c --- a/menu.c 2004-08-11 16:29:56 +02:00 +++ b/menu.c 2004-08-23 10:06:11 +02:00 @@ -168,7 +168,7 @@ if (option (OPTHELP)) { - SETCOLOR (MT_COLOR_STATUS); + SETCOLOR (MT_COLOR_STDEFAULT); move (option (OPTSTATUSONTOP) ? LINES-2 : 0, 0); mutt_paddstr (COLS, menu->help); SETCOLOR (MT_COLOR_NORMAL); @@ -191,7 +191,7 @@ char buf[STRING]; snprintf (buf, sizeof (buf), M_MODEFMT, menu->title); - SETCOLOR (MT_COLOR_STATUS); + SETCOLOR (MT_COLOR_STDEFAULT); move (option (OPTSTATUSONTOP) ? 0 : LINES - 2, 0); mutt_paddstr (COLS, buf); SETCOLOR (MT_COLOR_NORMAL); diff -Nru a/mutt_curses.h b/mutt_curses.h --- a/mutt_curses.h 2004-07-24 12:27:21 +02:00 +++ b/mutt_curses.h 2004-08-23 12:10:31 +02:00 @@ -107,7 +107,7 @@ MT_COLOR_QUOTED, MT_COLOR_SIGNATURE, MT_COLOR_INDICATOR, - MT_COLOR_STATUS, + MT_COLOR_STDEFAULT, MT_COLOR_TREE, MT_COLOR_NORMAL, MT_COLOR_ERROR, @@ -121,6 +121,7 @@ MT_COLOR_BOLD, MT_COLOR_UNDERLINE, MT_COLOR_INDEX, + MT_COLOR_STATUS, MT_COLOR_MAX }; @@ -141,6 +142,7 @@ extern int ColorDefs[]; extern COLOR_LINE *ColorHdrList; extern COLOR_LINE *ColorBodyList; +extern COLOR_LINE *ColorStatusList; extern COLOR_LINE *ColorIndexList; void ci_init_color (void); diff -Nru a/mutt_ssl_nss.c b/mutt_ssl_nss.c --- a/mutt_ssl_nss.c 2004-07-24 12:27:21 +02:00 +++ b/mutt_ssl_nss.c 2004-08-23 10:06:30 +02:00 @@ -178,7 +178,7 @@ addstr ("BAD"); move (LINES - 2, 0); - SETCOLOR (MT_COLOR_STATUS); + SETCOLOR (MT_COLOR_STDEFAULT); memset (status, ' ', sizeof (status) - 1); if (COLS < sizeof (status)) status[COLS - 1] = 0; diff -Nru a/pager.c b/pager.c --- a/pager.c 2004-07-24 12:27:21 +02:00 +++ b/pager.c 2004-08-23 10:06:58 +02:00 @@ -1590,7 +1590,7 @@ if (option (OPTHELP)) { - SETCOLOR (MT_COLOR_STATUS); + SETCOLOR (MT_COLOR_STDEFAULT); move (helpoffset, 0); mutt_paddstr (COLS, helpstr); SETCOLOR (MT_COLOR_NORMAL); @@ -1701,8 +1701,8 @@ if (redraw & REDRAW_STATUS) { /* print out the pager status bar */ - SETCOLOR (MT_COLOR_STATUS); - BKGDSET (MT_COLOR_STATUS); + SETCOLOR (MT_COLOR_STDEFAULT); + BKGDSET (MT_COLOR_STDEFAULT); CLEARLINE (statusoffset); if (IsHeader (extra)) { @@ -1737,7 +1737,7 @@ menu_status_line (buffer, sizeof (buffer), index, NONULL(Status)); move (indexoffset + (option (OPTSTATUSONTOP) ? 0 : (indexlen - 1)), 0); - SETCOLOR (MT_COLOR_STATUS); + SETCOLOR (MT_COLOR_STDEFAULT); mutt_paddstr (COLS, buffer); SETCOLOR (MT_COLOR_NORMAL); } diff -Nru a/remailer.c b/remailer.c --- a/remailer.c 2004-07-24 12:27:23 +02:00 +++ b/remailer.c 2004-08-23 10:07:18 +02:00 @@ -313,10 +313,10 @@ static void mix_redraw_head (MIXCHAIN *chain) { - SETCOLOR (MT_COLOR_STATUS); + SETCOLOR (MT_COLOR_STDEFAULT); mvprintw (MIX_VOFFSET - 1, 0, "-- Remailer chain [Length: %d]", chain ? chain->cl : 0); - BKGDSET (MT_COLOR_STATUS); + BKGDSET (MT_COLOR_STDEFAULT); clrtoeol (); BKGDSET (MT_COLOR_NORMAL);