Last active
October 10, 2015 19:40
-
-
Save knubie/e74b4f79f9b1dd5ec9b8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
commit d380436f3d34c19e7290364e29a92d785a9da842 | |
Author: Matt Steedman <[email protected]> | |
Date: Sat Oct 10 15:33:45 2015 -0400 | |
Apply indexcolor patch | |
diff --git a/color.c b/color.c | |
index 64a46dc..7c6a220 100644 | |
--- a/color.c | |
+++ b/color.c | |
@@ -35,6 +35,8 @@ int ColorDefs[MT_COLOR_MAX]; | |
COLOR_LINE *ColorHdrList = NULL; | |
COLOR_LINE *ColorBodyList = NULL; | |
COLOR_LINE *ColorIndexList = NULL; | |
+COLOR_LINE *ColorIndexSubjectList = NULL; | |
+COLOR_LINE *ColorIndexAuthorList = NULL; | |
/* local to this file */ | |
static int ColorQuoteSize; | |
@@ -93,6 +95,14 @@ static const struct mapping_t Fields[] = | |
{ "bold", MT_COLOR_BOLD }, | |
{ "underline", MT_COLOR_UNDERLINE }, | |
{ "index", MT_COLOR_INDEX }, | |
+ { "index_subject", MT_COLOR_INDEX_SUBJECT }, | |
+ { "index_author", MT_COLOR_INDEX_AUTHOR }, | |
+ { "index_collapsed", MT_COLOR_INDEX_COLLAPSED }, | |
+ { "index_date", MT_COLOR_INDEX_DATE }, | |
+ { "index_flags", MT_COLOR_INDEX_FLAGS }, | |
+ { "index_label", MT_COLOR_INDEX_LABEL }, | |
+ { "index_number", MT_COLOR_INDEX_NUMBER }, | |
+ { "index_size", MT_COLOR_INDEX_SIZE }, | |
{ "prompt", MT_COLOR_PROMPT }, | |
{ NULL, 0 } | |
}; | |
@@ -359,6 +369,19 @@ int mutt_parse_uncolor (BUFFER *buf, BUFFER *s, unsigned long data, | |
#endif | |
+static void | |
+mutt_do_uncolor (BUFFER *buf, BUFFER *s, COLOR_LINE **ColorList, | |
+ int *do_cache, int parse_uncolor) | |
+{ | |
+ COLOR_LINE *tmp, *last = NULL; | |
+ | |
+ if (object == MT_COLOR_INDEX) | |
+ mutt_do_uncolor(buf, s, &ColorIndexList, &do_cache, parse_uncolor); | |
+ if (object == MT_COLOR_INDEX_SUBJECT) | |
+ mutt_do_uncolor(buf, s, &ColorIndexSubjectList, &do_cache, parse_uncolor); | |
+ if (object == MT_COLOR_INDEX_AUTHOR) | |
+ mutt_do_uncolor(buf, s, &ColorIndexAuthorList, &do_cache, parse_uncolor); | |
+ | |
int mutt_parse_unmono (BUFFER *buf, BUFFER *s, unsigned long data, | |
BUFFER *err) | |
{ | |
@@ -380,6 +403,13 @@ static int _mutt_parse_uncolor (BUFFER *buf, BUFFER *s, unsigned long data, | |
return (-1); | |
} | |
+ if (object > MT_COLOR_INDEX_AUTHOR) /* uncolor index column */ | |
+ { | |
+ ColorDefs[object] = 0; | |
+ set_option (OPTFORCEREDRAWINDEX); | |
+ return (0); | |
+ } | |
+ | |
if (mutt_strncmp (buf->data, "index", 5) == 0) | |
list = &ColorIndexList; | |
else if (mutt_strncmp (buf->data, "body", 4) == 0) | |
@@ -699,7 +729,7 @@ _mutt_parse_color (BUFFER *buf, BUFFER *s, BUFFER *err, | |
/* 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_INDEX_SUBJECT || object == MT_COLOR_INDEX_AUTHOR) | |
{ | |
if (!MoreArgs (s)) | |
{ | |
@@ -743,6 +773,18 @@ _mutt_parse_color (BUFFER *buf, BUFFER *s, BUFFER *err, | |
r = add_pattern (&ColorIndexList, buf->data, 1, fg, bg, attr, err, 1); | |
set_option (OPTFORCEREDRAWINDEX); | |
} | |
+ else if (object == MT_COLOR_INDEX_SUBJECT) | |
+ { | |
+ r = add_pattern (&ColorIndexSubjectList, buf->data, | |
+ 1, fg, bg, attr, err, 1); | |
+ set_option (OPTFORCEREDRAWINDEX); | |
+ } | |
+ else if (object == MT_COLOR_INDEX_AUTHOR) | |
+ { | |
+ r = add_pattern (&ColorIndexAuthorList, buf->data, | |
+ 1, fg, bg, attr, err, 1); | |
+ set_option (OPTFORCEREDRAWINDEX); | |
+ } | |
else if (object == MT_COLOR_QUOTED) | |
{ | |
if (q_level >= ColorQuoteSize) | |
@@ -768,7 +810,11 @@ _mutt_parse_color (BUFFER *buf, BUFFER *s, BUFFER *err, | |
ColorQuote[q_level] = fgbgattr_to_color(fg, bg, attr); | |
} | |
else | |
+ { | |
ColorDefs[object] = fgbgattr_to_color(fg, bg, attr); | |
+ if (object > MT_COLOR_INDEX_AUTHOR) | |
+ set_option (OPTFORCEREDRAWINDEX); | |
+ } | |
return (r); | |
} | |
diff --git a/curs_lib.c b/curs_lib.c | |
index d8c62c3..667b0ea 100644 | |
--- a/curs_lib.c | |
+++ b/curs_lib.c | |
@@ -726,6 +726,7 @@ void mutt_format_string (char *dest, size_t destlen, | |
size_t k, k2; | |
char scratch[MB_LEN_MAX]; | |
mbstate_t mbstate1, mbstate2; | |
+ int escaped = 0; | |
memset(&mbstate1, 0, sizeof (mbstate1)); | |
memset(&mbstate2, 0, sizeof (mbstate2)); | |
@@ -741,7 +742,15 @@ void mutt_format_string (char *dest, size_t destlen, | |
k = (k == (size_t)(-1)) ? 1 : n; | |
wc = replacement_char (); | |
} | |
- if (arboreal && wc < M_TREE_MAX) | |
+ if (escaped) { | |
+ escaped = 0; | |
+ w = 0; | |
+ } | |
+ else if (arboreal && wc == M_SPECIAL_INDEX) { | |
+ escaped = 1; | |
+ w = 0; | |
+ } | |
+ else if (arboreal && wc < M_TREE_MAX) | |
w = 1; /* hack */ | |
else | |
{ | |
diff --git a/doc/manual.xml.head b/doc/manual.xml.head | |
index baeddac..6288493 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. | |
<command>color</command> | |
<arg choice="plain"> | |
-<option>index</option> | |
+<option>object</option> | |
</arg> | |
<arg choice="plain"> | |
<replaceable class="parameter">foreground</replaceable> | |
@@ -2612,7 +2612,7 @@ silently truncated at the screen width, and are not wrapped. | |
<command>uncolor</command> | |
<group choice="req"> | |
<arg choice="plain"> | |
-<option>index</option> | |
+<option>object</option> | |
</arg> | |
<arg choice="plain"> | |
<option>header</option> | |
@@ -2657,6 +2657,14 @@ patterns. | |
<listitem><para>bold (highlighting bold patterns in the body of messages)</para></listitem> | |
<listitem><para>error (error messages printed by Mutt)</para></listitem> | |
<listitem><para>hdrdefault (default color of the message header in the pager)</para></listitem> | |
+<listitem><para>index_author (color of the author name in the index, uses <emphasis>pattern</emphasis>)</para></listitem> | |
+<listitem><para>index_collapsed (the number of messages in a collapsed thread in the index)</para></listitem> | |
+<listitem><para>index_date (color of the date field in the index)</para></listitem> | |
+<listitem><para>index_flags (color of the message flags in the index)</para></listitem> | |
+<listitem><para>index_label (color of the message label in the index)</para></listitem> | |
+<listitem><para>index_number (color of the message number in the index)</para></listitem> | |
+<listitem><para>index_size (color of the message size and line number in the index)</para></listitem> | |
+<listitem><para>index_subject (color of the subject in the index, uses <emphasis>pattern</emphasis>)</para></listitem> | |
<listitem><para>indicator (arrow or bar used to indicate the current item in a menu)</para></listitem> | |
<listitem><para>markers (the <quote>+</quote> markers at the beginning of wrapped lines in the pager)</para></listitem> | |
<listitem><para>message (informational messages)</para></listitem> | |
diff --git a/hdrline.c b/hdrline.c | |
index 21adc28..d5845d4 100644 | |
--- a/hdrline.c | |
+++ b/hdrline.c | |
@@ -103,6 +103,34 @@ static int first_mailing_list (char *buf, size_t buflen, ADDRESS *a) | |
return 0; | |
} | |
+/* Takes the color to embed, the buffer to manipulate and the buffer length as | |
+ * arguments. | |
+ * Returns the number of chars written. */ | |
+static size_t add_index_color(char *buf, size_t buflen, | |
+ format_flag flags, char color) | |
+{ | |
+ int len; | |
+ | |
+ /* only add color markers if we are operating on main index entries. */ | |
+ if (!(flags & M_FORMAT_INDEX)) | |
+ return 0; | |
+ | |
+ if (color == MT_COLOR_INDEX) { /* buf might be uninitialized other cases */ | |
+ len = mutt_strlen(buf); | |
+ buf += len; | |
+ buflen -= len; | |
+ } | |
+ | |
+ if (buflen < 2) | |
+ return 0; | |
+ | |
+ buf[0] = M_SPECIAL_INDEX; | |
+ buf[1] = color; | |
+ buf[2] = '\0'; | |
+ | |
+ return 2; | |
+} | |
+ | |
static void make_from (ENVELOPE *hdr, char *buf, size_t len, int do_lists) | |
{ | |
int me; | |
@@ -253,6 +281,7 @@ hdr_format_str (char *dest, | |
#define THREAD_NEW (threads && hdr->collapsed && hdr->num_hidden > 1 && mutt_thread_contains_unread (ctx, hdr) == 1) | |
#define THREAD_OLD (threads && hdr->collapsed && hdr->num_hidden > 1 && mutt_thread_contains_unread (ctx, hdr) == 2) | |
size_t len; | |
+ size_t colorlen; | |
hdr = hfi->hdr; | |
ctx = hfi->ctx; | |
@@ -304,12 +333,17 @@ hdr_format_str (char *dest, | |
break; | |
case 'c': | |
+ colorlen = add_index_color(dest, destlen, flags, MT_COLOR_INDEX_SIZE); | |
mutt_pretty_size (buf2, sizeof (buf2), (long) hdr->content->length); | |
- mutt_format_s (dest, destlen, prefix, buf2); | |
+ mutt_format_s (dest+colorlen, destlen-colorlen, prefix, buf2); | |
+ add_index_color(dest+colorlen, destlen-colorlen, flags, MT_COLOR_INDEX); | |
break; | |
case 'C': | |
- snprintf (fmt, sizeof (fmt), "%%%sd", prefix); | |
+ colorlen = add_index_color(fmt, sizeof(fmt), flags, MT_COLOR_INDEX_NUMBER); | |
+ snprintf (fmt+colorlen, sizeof(fmt)-colorlen, "%%%sd", prefix); | |
+ add_index_color(fmt+colorlen, sizeof(fmt)-colorlen, flags, MT_COLOR_INDEX); | |
+ | |
snprintf (dest, destlen, fmt, hdr->msgno + 1); | |
break; | |
@@ -408,7 +442,10 @@ hdr_format_str (char *dest, | |
if (do_locales) | |
setlocale (LC_TIME, "C"); | |
- mutt_format_s (dest, destlen, prefix, buf2); | |
+ colorlen = add_index_color(dest, destlen, flags, MT_COLOR_INDEX_DATE); | |
+ mutt_format_s (dest+colorlen, destlen-colorlen, prefix, buf2); | |
+ add_index_color(dest+colorlen, destlen-colorlen, flags, MT_COLOR_INDEX); | |
+ | |
if (len > 0 && op != 'd' && op != 'D') /* Skip ending op */ | |
src = cp + 1; | |
} | |
@@ -438,8 +475,10 @@ hdr_format_str (char *dest, | |
case 'F': | |
if (!optional) | |
{ | |
+ colorlen = add_index_color(dest, destlen, flags, MT_COLOR_INDEX_AUTHOR); | |
make_from (hdr->env, buf2, sizeof (buf2), 0); | |
- mutt_format_s (dest, destlen, prefix, buf2); | |
+ mutt_format_s (dest+colorlen, destlen-colorlen, prefix, buf2); | |
+ add_index_color(dest+colorlen, destlen-colorlen, flags, MT_COLOR_INDEX); | |
} | |
else if (mutt_addr_is_user (hdr->env->from)) | |
optional = 0; | |
@@ -465,7 +504,9 @@ hdr_format_str (char *dest, | |
if (!optional) | |
{ | |
snprintf (fmt, sizeof (fmt), "%%%sd", prefix); | |
- snprintf (dest, destlen, fmt, (int) hdr->lines); | |
+ colorlen = add_index_color(dest, destlen, flags, MT_COLOR_INDEX_SIZE); | |
+ snprintf (dest+colorlen, destlen-colorlen, fmt, (int) hdr->lines); | |
+ add_index_color(dest+colorlen, destlen-colorlen, flags, MT_COLOR_INDEX); | |
} | |
else if (hdr->lines <= 0) | |
optional = 0; | |
@@ -474,8 +515,10 @@ hdr_format_str (char *dest, | |
case 'L': | |
if (!optional) | |
{ | |
+ colorlen = add_index_color(dest, destlen, flags, MT_COLOR_INDEX_AUTHOR); | |
make_from (hdr->env, buf2, sizeof (buf2), 1); | |
- mutt_format_s (dest, destlen, prefix, buf2); | |
+ mutt_format_s (dest+colorlen, destlen-colorlen, prefix, buf2); | |
+ add_index_color(dest+colorlen, destlen-colorlen, flags, MT_COLOR_INDEX); | |
} | |
else if (!check_for_mailing_list (hdr->env->to, NULL, NULL, 0) && | |
!check_for_mailing_list (hdr->env->cc, NULL, NULL, 0)) | |
@@ -530,10 +573,16 @@ hdr_format_str (char *dest, | |
snprintf (fmt, sizeof (fmt), "%%%sd", prefix); | |
if (!optional) | |
{ | |
- if (threads && is_index && hdr->collapsed && hdr->num_hidden > 1) | |
- snprintf (dest, destlen, fmt, hdr->num_hidden); | |
- else if (is_index && threads) | |
- mutt_format_s (dest, destlen, prefix, " "); | |
+ colorlen = add_index_color(dest, destlen, flags, | |
+ MT_COLOR_INDEX_COLLAPSED); | |
+ if (threads && is_index && hdr->collapsed && hdr->num_hidden > 1) { | |
+ snprintf (dest+colorlen, destlen-colorlen, fmt, hdr->num_hidden); | |
+ add_index_color(dest, destlen-colorlen, flags, MT_COLOR_INDEX); | |
+ } | |
+ else if (is_index && threads) { | |
+ mutt_format_s (dest+colorlen, destlen-colorlen, prefix, " "); | |
+ add_index_color(dest, destlen-colorlen, flags, MT_COLOR_INDEX); | |
+ } | |
else | |
*dest = '\0'; | |
} | |
@@ -554,15 +603,22 @@ hdr_format_str (char *dest, | |
{ | |
if (flags & M_FORMAT_FORCESUBJ) | |
{ | |
- mutt_format_s (dest, destlen, "", NONULL (hdr->env->subject)); | |
+ colorlen = add_index_color(dest, destlen, flags, MT_COLOR_INDEX_SUBJECT); | |
+ mutt_format_s (dest+colorlen, destlen-colorlen, "", | |
+ NONULL (hdr->env->subject)); | |
+ add_index_color(dest+colorlen, destlen-colorlen, flags, MT_COLOR_INDEX); | |
snprintf (buf2, sizeof (buf2), "%s%s", hdr->tree, dest); | |
mutt_format_s_tree (dest, destlen, prefix, buf2); | |
} | |
else | |
mutt_format_s_tree (dest, destlen, prefix, hdr->tree); | |
} | |
- else | |
- mutt_format_s (dest, destlen, prefix, NONULL (hdr->env->subject)); | |
+ else { | |
+ colorlen = add_index_color(dest, destlen, flags, MT_COLOR_INDEX_SUBJECT); | |
+ mutt_format_s (dest+colorlen, destlen-colorlen, prefix, | |
+ + NONULL (hdr->env->subject)); | |
+ add_index_color(dest+colorlen, destlen-colorlen, flags, MT_COLOR_INDEX); | |
+ } | |
break; | |
case 'S': | |
@@ -658,7 +714,9 @@ hdr_format_str (char *dest, | |
hdr->tagged ? '*' : | |
(hdr->flagged ? '!' : | |
(Tochars && ((i = mutt_user_is_recipient (hdr)) < mutt_strlen (Tochars)) ? Tochars[i] : ' '))); | |
- mutt_format_s (dest, destlen, prefix, buf2); | |
+ 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 'X': | |
@@ -678,7 +736,9 @@ hdr_format_str (char *dest, | |
if (optional) | |
optional = hdr->env->x_label ? 1 : 0; | |
- mutt_format_s (dest, destlen, prefix, NONULL (hdr->env->x_label)); | |
+ colorlen = add_index_color(dest, destlen, flags, MT_COLOR_INDEX_LABEL); | |
+ mutt_format_s (dest+colorlen, destlen-colorlen, prefix, NONULL (hdr->env->x_label)); | |
+ add_index_color(dest+colorlen, destlen-colorlen, flags, MT_COLOR_INDEX); | |
break; | |
case 'Y': | |
@@ -704,10 +764,12 @@ hdr_format_str (char *dest, | |
if (optional) | |
optional = i; | |
+ colorlen = add_index_color(dest, destlen, flags, MT_COLOR_INDEX_LABEL); | |
if (i) | |
- mutt_format_s (dest, destlen, prefix, NONULL (hdr->env->x_label)); | |
+ mutt_format_s (dest+colorlen, destlen-colorlen, prefix, NONULL (hdr->env->x_label)); | |
else | |
- mutt_format_s (dest, destlen, prefix, ""); | |
+ mutt_format_s (dest+colorlen, destlen-colorlen, prefix, ""); | |
+ add_index_color(dest+colorlen, destlen-colorlen, flags, MT_COLOR_INDEX); | |
break; | |
diff --git a/menu.c b/menu.c | |
index e03dd33..4b7f140 100644 | |
--- a/menu.c | |
+++ b/menu.c | |
@@ -29,7 +29,30 @@ extern size_t UngetCount; | |
char* SearchBuffers[MENU_MAX]; | |
-static void print_enriched_string (int attr, unsigned char *s, int do_color) | |
+static int get_color(int index, int type) { | |
+ COLOR_LINE *color; | |
+ HEADER *hdr = Context->hdrs[index]; | |
+ | |
+ switch (type) { | |
+ case MT_COLOR_INDEX_SUBJECT: | |
+ color = ColorIndexSubjectList; | |
+ break; | |
+ case MT_COLOR_INDEX_AUTHOR: | |
+ color = ColorIndexAuthorList; | |
+ break; | |
+ default: | |
+ return ColorDefs[type]; | |
+ } | |
+ | |
+ for (; color; color = color->next) | |
+ if (mutt_pattern_exec (color->color_pattern, M_MATCH_FULL_ADDRESS, | |
+ + Context, hdr)) | |
+ return color->pair; | |
+ | |
+ return 0; | |
+} | |
+ | |
+static void print_enriched_string (int index, int attr, unsigned char *s, int do_color) | |
{ | |
wchar_t wc; | |
size_t k; | |
@@ -161,6 +184,18 @@ static void print_enriched_string (int attr, unsigned char *s, int do_color) | |
} | |
if (do_color) ATTRSET(attr); | |
} | |
+ else if(*s == M_SPECIAL_INDEX) | |
+ { | |
+ s++; | |
+ if (do_color) { | |
+ if (*s == MT_COLOR_INDEX) | |
+ attrset(attr); | |
+ else | |
+ attron(get_color(index, *s)); | |
+ } | |
+ s++; | |
+ n -= 2; | |
+ } | |
else if ((k = mbrtowc (&wc, (char *)s, n, &mbstate)) > 0) | |
{ | |
addnstr ((char *)s, k); | |
diff --git a/mutt.h b/mutt.h | |
index f8565fa..d428122 100644 | |
--- a/mutt.h | |
+++ b/mutt.h | |
@@ -161,6 +161,8 @@ typedef enum | |
#define M_TREE_MISSING 13 | |
#define M_TREE_MAX 14 | |
++#define M_SPECIAL_INDEX M_TREE_MAX | |
+ | |
#define M_THREAD_COLLAPSE (1<<0) | |
#define M_THREAD_UNCOLLAPSE (1<<1) | |
#define M_THREAD_GET_HIDDEN (1<<2) | |
diff --git a/mutt_curses.h b/mutt_curses.h | |
index f8bc47c..53cb284 100644 | |
--- a/mutt_curses.h | |
+++ b/mutt_curses.h | |
@@ -120,6 +120,16 @@ enum | |
MT_COLOR_BOLD, | |
MT_COLOR_UNDERLINE, | |
MT_COLOR_INDEX, | |
+ /* please no non-MT_COLOR_INDEX objects after this point */ | |
+ MT_COLOR_INDEX_SUBJECT, | |
+ MT_COLOR_INDEX_AUTHOR, | |
+ /* below only index coloring stuff that doesn't have a colorline! */ | |
+ MT_COLOR_INDEX_COLLAPSED, | |
+ MT_COLOR_INDEX_DATE, | |
+ MT_COLOR_INDEX_FLAGS, | |
+ MT_COLOR_INDEX_LABEL, | |
+ MT_COLOR_INDEX_NUMBER, | |
+ MT_COLOR_INDEX_SIZE, | |
MT_COLOR_PROMPT, | |
MT_COLOR_MAX | |
}; | |
@@ -174,6 +184,8 @@ extern int ColorDefs[]; | |
extern COLOR_LINE *ColorHdrList; | |
extern COLOR_LINE *ColorBodyList; | |
extern COLOR_LINE *ColorIndexList; | |
+extern COLOR_LINE *ColorIndexSubjectList; | |
+extern COLOR_LINE *ColorIndexAuthorList; | |
void ci_init_color (void); | |
void ci_start_color (void); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment