diff -Nru a/PATCHES b/PATCHES --- a/PATCHES +++ b/PATCHES @@ -0,0 +1 @@ +patch-HEAD.tg.cstatus.5 diff -Nru a/color.c b/color.c --- a/color.c 2005-01-27 20:46:52 +01:00 +++ b/color.c 2005-01-28 16:04:05 +01: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 */ @@ -466,7 +467,7 @@ static int add_pattern (COLOR_LINE **top, const char *s, int sensitive, int fg, int bg, int attr, BUFFER *err, - int is_index) + int is_index, int match) { /* is_index used to store compiled pattern @@ -537,6 +538,7 @@ } tmp->next = *top; tmp->pattern = safe_strdup (s); + tmp->match = match; #ifdef HAVE_COLOR if(fg != -1 && bg != -1) { @@ -679,7 +681,7 @@ parser_callback_t callback, short dry_run) { int object = 0, attr = 0, fg = 0, bg = 0, q_level = 0; - int r = 0; + int r = 0, match = 0; if(parse_object(buf, s, &object, &q_level, err) == -1) return -1; @@ -687,8 +689,6 @@ if(callback(buf, s, &fg, &bg, &attr, err) == -1) return -1; - /* extract a regular expression if needed */ - if (object == MT_COLOR_HEADER || object == MT_COLOR_BODY || object == MT_COLOR_INDEX) { if (!MoreArgs (s)) @@ -700,7 +700,7 @@ mutt_extract_token (buf, s, 0); } - if (MoreArgs (s)) + if (MoreArgs (s) && object != MT_COLOR_STATUS) { strfcpy (err->data, _("too many arguments"), err->dsize); return (-1); @@ -725,12 +725,37 @@ #endif if (object == MT_COLOR_HEADER) - r = add_pattern (&ColorHdrList, buf->data, 0, fg, bg, attr, err,0); + r = add_pattern (&ColorHdrList, buf->data, 0, fg, bg, attr, err, 0, match); else if (object == MT_COLOR_BODY) - r = add_pattern (&ColorBodyList, buf->data, 1, fg, bg, attr, err, 0); + r = add_pattern (&ColorBodyList, buf->data, 1, fg, bg, attr, err, 0, match); + else if (object == MT_COLOR_STATUS && MoreArgs(s)) + { + /* 'color status fg bg' can have upto 2 arguments: + * 0 arguments: sets the default status color (handled below by else part) + * 1 argument : colorize pattern on match + * 2 arguments: colorize nth submatch of pattern + */ + mutt_extract_token (buf, s, 0); + + if (MoreArgs(s)) { + BUFFER temporary; + memset(&temporary, 0, sizeof(BUFFER)); + mutt_extract_token(&temporary, s, 0); + match = atoi(temporary.data); + FREE(&temporary.data); + } + + if (MoreArgs(s)) + { + strfcpy (err->data, _("too many arguments"), err->dsize); + return (-1); + } + + r = add_pattern (&ColorStatusList, buf->data, 1, fg, bg, attr, err, 0, match); + } else if (object == MT_COLOR_INDEX) { - r = add_pattern (&ColorIndexList, buf->data, 1, fg, bg, attr, err, 1); + r = add_pattern (&ColorIndexList, buf->data, 1, fg, bg, attr, err, 1, match); set_option (OPTFORCEREDRAWINDEX); } else if (object == MT_COLOR_QUOTED) diff -Nru a/curs_main.c b/curs_main.c --- a/curs_main.c 2005-01-27 22:17:46 +01:00 +++ b/curs_main.c 2005-01-28 16:04:05 +01:00 @@ -393,6 +393,117 @@ menu->redraw = REDRAW_INDEX | REDRAW_STATUS; } +void +mutt_draw_statusline(int cols, char *inbuf) +{ + int i = 0; + int cnt = 0; + int last_color = 0; + int color = 0; + int offset = 0; + int found = 0; + int null_rx = 0; + unsigned char buf[2048]; + + struct line_t { + short chunks; + struct syntax_t { + int color; + int first; + int last; + } *syntax; + } lineInfo = { 0, 0 }; + + mutt_format_string(buf, sizeof(buf), cols, cols, 0, ' ', inbuf, + mutt_strlen(inbuf), 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_STATUS]; + lineInfo.chunks = 1; + + do + { + found = 0; + null_rx = 0; + COLOR_LINE *color_line = ColorStatusList; + + if (!buf[offset]) + break; + + while (color_line) + { + regmatch_t pmatch[color_line->match + 1]; + + if (regexec (&color_line->rx, buf + offset, color_line->match + 1, pmatch, + (offset ? REG_NOTBOL : 0)) == 0) + { + if (pmatch[color_line->match].rm_eo != pmatch[color_line->match].rm_so) + { + if (!found) + { + if (++(lineInfo.chunks) > 1) + safe_realloc (&(lineInfo.syntax), + (lineInfo.chunks) * sizeof (struct syntax_t)); + } + i = lineInfo.chunks - 1; + pmatch[color_line->match].rm_so += offset; + pmatch[color_line->match].rm_eo += offset; + if (!found || + pmatch[color_line->match].rm_so < (lineInfo.syntax)[i].first || + (pmatch[color_line->match].rm_so == (lineInfo.syntax)[i].first && + pmatch[color_line->match].rm_eo > (lineInfo.syntax)[i].last)) + { + (lineInfo.syntax)[i].color = color_line->pair; + (lineInfo.syntax)[i].first = pmatch[color_line->match].rm_so; + (lineInfo.syntax)[i].last = pmatch[color_line->match].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 }, @@ -559,7 +670,7 @@ menu_status_line (buf, sizeof (buf), menu, NONULL (Status)); CLEARLINE (option (OPTSTATUSONTOP) ? 0 : LINES-2); SETCOLOR (MT_COLOR_STATUS); - mutt_paddstr (COLS, buf); + mutt_draw_statusline(COLS, buf); SETCOLOR (MT_COLOR_NORMAL); menu->redraw &= ~REDRAW_STATUS; } 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-09-26 12:14:42 +02:00 @@ -127,6 +127,7 @@ typedef struct color_line { regex_t rx; + int match; /* which substringmap 0 for old behaviour */ char *pattern; pattern_t *color_pattern; /* compiled pattern to speed up index color calculation */ @@ -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/pager.c b/pager.c --- a/pager.c 2004-07-24 12:27:21 +02:00 +++ b/pager.c 2004-09-26 12:03:00 +02:00 @@ -1700,10 +1700,11 @@ if (redraw & REDRAW_STATUS) { + char temporary[2048]; /* XXX --tg 01:06 04-08-26 */ + /* print out the pager status bar */ SETCOLOR (MT_COLOR_STATUS); BKGDSET (MT_COLOR_STATUS); - CLEARLINE (statusoffset); if (IsHeader (extra)) { _mutt_make_string (buffer, @@ -1716,13 +1717,24 @@ COLS - 9 < sizeof (buffer) ? COLS - 9: sizeof (buffer), NONULL (PagerFmt), Context, extra->bdy->hdr, M_FORMAT_MAKEPRINT); } - mutt_paddstr (COLS-10, IsHeader (extra) || IsMsgAttach (extra) ? - buffer : banner); - addstr (" -- ("); + + if (IsHeader (extra) || IsMsgAttach (extra)) + strcpy(temporary, buffer); + else + strcpy(temporary, banner); + + while (strlen(temporary) < (COLS - 10)) + strcat(temporary, " "); + + strcat(temporary, " -- ("); + if (last_pos < sb.st_size - 1) - printw ("%d%%)", (int) (100 * last_offset / sb.st_size)); + sprintf(temporary + strlen(temporary), "%d%%) ", (int) (100 * last_offset / sb.st_size)); else - addstr (topline == 0 ? "all)" : "end)"); + strcat(temporary, (topline == 0 ? "all) " : "end) ")); + + mutt_draw_statusline (COLS, temporary); + BKGDSET (MT_COLOR_NORMAL); SETCOLOR (MT_COLOR_NORMAL); } @@ -1738,7 +1750,7 @@ move (indexoffset + (option (OPTSTATUSONTOP) ? 0 : (indexlen - 1)), 0); SETCOLOR (MT_COLOR_STATUS); - mutt_paddstr (COLS, buffer); + mutt_draw_statusline(COLS, buffer); SETCOLOR (MT_COLOR_NORMAL); } diff -Nru a/protos.h b/protos.h --- a/protos.h 2005-01-31 04:40:14 +01:00 +++ b/protos.h 2005-02-01 07:18:08 +01:00 @@ -180,6 +180,7 @@ void mutt_default_save (char *, size_t, HEADER *); void mutt_display_address (ENVELOPE *); void mutt_display_sanitize (char *); +void mutt_draw_statusline(int n, char *); void mutt_edit_content_type (HEADER *, BODY *, FILE *); void mutt_edit_file (const char *, const char *); void mutt_edit_headers (const char *, const char *, HEADER *, char *, size_t);