From 02f781bc877c1e3b2f916bc359726403dfaa0374 Mon Sep 17 00:00:00 2001 From: Eric Davis Date: Sun, 31 Jan 2016 00:21:21 +0000 Subject: [PATCH] add handling index flags --- color.c | 12 +++++++++++- doc/manual.xml.head | 28 +++++++++++++++++++++++----- hdrline.c | 19 ++++++++++++++----- menu.c | 15 ++++++++++++--- mutt_curses.h | 5 +++-- 5 files changed, 63 insertions(+), 16 deletions(-) diff --git a/color.c b/color.c index c2fc7646d..874fe9625 100644 --- a/color.c +++ b/color.c @@ -37,6 +37,7 @@ COLOR_LINE *ColorBodyList = NULL; COLOR_LINE *ColorIndexList = NULL; COLOR_LINE *ColorIndexSubjectList = NULL; COLOR_LINE *ColorIndexAuthorList = NULL; +COLOR_LINE *ColorIndexFlagsList = NULL; /* local to this file */ static int ColorQuoteSize; @@ -484,6 +485,8 @@ static int _mutt_parse_uncolor (BUFFER *buf, BUFFER *s, unsigned long data, mutt_do_uncolor(buf, s, &ColorIndexSubjectList, &do_cache, parse_uncolor); else if (object == MT_COLOR_INDEX_AUTHOR) mutt_do_uncolor(buf, s, &ColorIndexAuthorList, &do_cache, parse_uncolor); + else if (object == MT_COLOR_INDEX_FLAGS) + mutt_do_uncolor(buf, s, &ColorIndexFlagsList, &do_cache, parse_uncolor); if (do_cache && !option (OPTNOCURSES)) { @@ -727,7 +730,8 @@ _mutt_parse_color (BUFFER *buf, BUFFER *s, BUFFER *err, object == MT_COLOR_BODY || object == MT_COLOR_INDEX || object == MT_COLOR_INDEX_SUBJECT || - object == MT_COLOR_INDEX_AUTHOR) + object == MT_COLOR_INDEX_AUTHOR || + object == MT_COLOR_INDEX_FLAGS) { if (!MoreArgs (s)) { @@ -783,6 +787,12 @@ _mutt_parse_color (BUFFER *buf, BUFFER *s, BUFFER *err, 1, fg, bg, attr, err, 1); set_option (OPTFORCEREDRAWINDEX); } + else if (object == MT_COLOR_INDEX_FLAGS) + { + r = add_pattern (&ColorIndexFlagsList, buf->data, + 1, fg, bg, attr, err, 1); + set_option (OPTFORCEREDRAWINDEX); + } else if (object == MT_COLOR_QUOTED) { if (q_level >= ColorQuoteSize) diff --git a/doc/manual.xml.head b/doc/manual.xml.head index cf3cf35da..0cbf4e479 100644 --- a/doc/manual.xml.head +++ b/doc/manual.xml.head @@ -2597,7 +2597,7 @@ silently truncated at the screen width, and are not wrapped. color - + foreground @@ -2612,7 +2612,7 @@ silently truncated at the screen width, and are not wrapped. uncolor - + @@ -2642,8 +2642,8 @@ specify one or the other). header and body match regexp in the header/body of a message, -index matches pattern (see -) in the message index. Note that IMAP +index-object can match pattern +(see ) in the message index. Note that IMAP server-side searches (=b, =B, =h) are not supported for color index patterns. @@ -2679,6 +2679,24 @@ patterns. underline (highlighting underlined patterns in the body of messages) + +index-object can be one of the following: + + + +index (default highlighting of the entire index line, uses pattern) +index_date (the date field) +index_flags (the message flags, %S %Z, uses pattern) +index_number (the message number, %C) +index_collapsed (the number of messages in a collapsed thread, %M) +index_author (the author name, %A %a %F %L %n, uses pattern) +index_subject (the subject, %s, uses pattern) +index_size (the message size, %c %l) +index_label (the message label, %y %Y) +index_tags (the transformed message tags, %g) +index_tag (an individual message tag, %G, uses pattern / tag name) + + foreground and background can be one of the following: @@ -2796,7 +2814,7 @@ command. Usage: unmono - + diff --git a/hdrline.c b/hdrline.c index ce2384f66..5d0ea0074 100644 --- a/hdrline.c +++ b/hdrline.c @@ -292,7 +292,9 @@ hdr_format_str (char *dest, case 'A': if(hdr->env->reply_to && hdr->env->reply_to->mailbox) { - mutt_format_s (dest, destlen, prefix, mutt_addr_for_display (hdr->env->reply_to)); + colorlen = add_index_color(dest, destlen, flags, MT_COLOR_INDEX_AUTHOR); + mutt_format_s (dest+colorlen, destlen-colorlen, prefix, mutt_addr_for_display (hdr->env->reply_to)); + add_index_color(dest+colorlen, destlen-colorlen, flags, MT_COLOR_INDEX); break; } /* fall through if 'A' returns nothing */ @@ -300,7 +302,9 @@ hdr_format_str (char *dest, case 'a': if(hdr->env->from && hdr->env->from->mailbox) { - mutt_format_s (dest, destlen, prefix, mutt_addr_for_display (hdr->env->from)); + colorlen = add_index_color(dest, destlen, flags, MT_COLOR_INDEX_AUTHOR); + mutt_format_s (dest+colorlen, destlen-colorlen, prefix, mutt_addr_for_display (hdr->env->from)); + add_index_color(dest+colorlen, destlen-colorlen, flags, MT_COLOR_INDEX); } else dest[0] = '\0'; @@ -537,7 +541,9 @@ hdr_format_str (char *dest, break; case 'n': - mutt_format_s (dest, destlen, prefix, mutt_get_name (hdr->env->from)); + colorlen = add_index_color(dest, destlen, flags, MT_COLOR_INDEX_AUTHOR); + mutt_format_s (dest+colorlen, destlen-colorlen, prefix, mutt_get_name (hdr->env->from)); + add_index_color(dest+colorlen, destlen-colorlen, flags, MT_COLOR_INDEX); break; case 'N': @@ -638,8 +644,11 @@ hdr_format_str (char *dest, /* FOO - this is probably unsafe, but we are not likely to have such a short string passed into this routine */ - *dest = ch; - *(dest + 1) = 0; + buf2[0] = ch; + buf2[1] = 0; + colorlen = add_index_color(dest, destlen, flags, MT_COLOR_INDEX_FLAGS); + mutt_format_s (dest+colorlen, destlen-colorlen, prefix, buf2); + add_index_color(dest+colorlen, destlen-colorlen, flags, MT_COLOR_INDEX); break; case 't': diff --git a/menu.c b/menu.c index 9867a7321..87046968f 100644 --- a/menu.c +++ b/menu.c @@ -29,9 +29,10 @@ extern size_t UngetCount; char* SearchBuffers[MENU_MAX]; -static int get_color(int index, int type) { +static int get_color(int index, unsigned char *s) { COLOR_LINE *color; - HEADER *hdr = Context->hdrs[index]; + HEADER *hdr = Context->hdrs[Context->v2r[index]]; + int type = *s; switch (type) { case MT_COLOR_INDEX_SUBJECT: @@ -40,6 +41,9 @@ static int get_color(int index, int type) { case MT_COLOR_INDEX_AUTHOR: color = ColorIndexAuthorList; break; + case MT_COLOR_INDEX_FLAGS: + color = ColorIndexFlagsList; + break; default: return ColorDefs[type]; } @@ -191,7 +195,12 @@ static void print_enriched_string (int index, int attr, unsigned char *s, int do if (*s == MT_COLOR_INDEX) attrset(attr); else - attron(get_color(index, *s)); + { + if (get_color(index, s) == 0) + attron(attr); + else + attron(get_color(index, s)); + } } s++; n -= 2; diff --git a/mutt_curses.h b/mutt_curses.h index 9d85363c3..9fd1a0861 100644 --- a/mutt_curses.h +++ b/mutt_curses.h @@ -123,11 +123,11 @@ enum /* please no non-MT_COLOR_INDEX objects after this point */ MT_COLOR_INDEX, MT_COLOR_INDEX_AUTHOR, + MT_COLOR_INDEX_FLAGS, MT_COLOR_INDEX_SUBJECT, - /* below only index coloring stuff that doesn't have a colorline! */ + /* below here - only index coloring stuff that doesn't have a pattern */ MT_COLOR_INDEX_COLLAPSED, MT_COLOR_INDEX_DATE, - MT_COLOR_INDEX_FLAGS, MT_COLOR_INDEX_LABEL, MT_COLOR_INDEX_NUMBER, MT_COLOR_INDEX_SIZE, @@ -186,6 +186,7 @@ extern COLOR_LINE *ColorBodyList; extern COLOR_LINE *ColorIndexList; extern COLOR_LINE *ColorIndexSubjectList; extern COLOR_LINE *ColorIndexAuthorList; +extern COLOR_LINE *ColorIndexFlagsList; void ci_init_color (void); void ci_start_color (void); -- 2.49.0