From 3a1e1d5e697b4a96ed897e4a85b2fa5a34a4511a Mon Sep 17 00:00:00 2001 From: somini Date: Sun, 1 Jan 2017 12:37:54 +0000 Subject: [PATCH] Allow custom status flags in index_format The commit introduces the variable $flag_chars. It allows the user to customise the status flags show in the index. $flag_chars affects both %S and %Z. $flag_chars defaults to "*!DdrONon- " Char | Default | Description ------|---------|---------------------------------------------- 1 | * | The mail is tagged 2 | ! | The mail is flagged as important 3 | D | The mail is marked for deletion 4 | d | The mail has attachments marked for deletion 5 | r | The mail has been replied to 6 | O | The mail is Old (Unread but seen) 7 | N | The mail is New (Unread but not seen) 8 | o | The mail thread is Old (Unread but seen) 9 | n | The mail thread is New (Unread but not seen) 10 | - | The mail is read - %S expando 11 | | The mail is read - %Z expando Closes: #275 --- globals.h | 1 + hdrline.c | 132 ++++++++++++++++++++++++++++++++++++++++-------------- init.h | 19 ++++++++ mutt.h | 3 +- 4 files changed, 121 insertions(+), 34 deletions(-) diff --git a/globals.h b/globals.h index 55e7d871c..9be77dbbd 100644 --- a/globals.h +++ b/globals.h @@ -163,6 +163,7 @@ WHERE mbchar_table *StChars; WHERE char *Status; WHERE char *Tempdir; WHERE mbchar_table *Tochars; +WHERE mbchar_table *Flagchars; WHERE char *TrashPath; WHERE char *TSStatusFormat; WHERE char *TSIconFormat; diff --git a/hdrline.c b/hdrline.c index 420b7c7aa..924270917 100644 --- a/hdrline.c +++ b/hdrline.c @@ -42,6 +42,22 @@ #include "mutt_notmuch.h" #endif +enum +{ + /* Indexing into the Flagchars variable ($flag_chars) */ + FlagCharTagged, + FlagCharImportant, + FlagCharDeleted, + FlagCharDeletedAttach, + FlagCharReplied, + FlagCharOld, + FlagCharNew, + FlagCharOldThread, + FlagCharNewThread, + FlagCharSEmpty, + FlagCharZEmpty +}; + int mutt_is_mail_list (ADDRESS *addr) { if (!mutt_match_rx_list (addr->mailbox, UnMailLists)) @@ -366,6 +382,27 @@ static int get_initials(const char *name, char *buf, int buflen) return 1; } +/** + * get_nth_wchar - Extract one char from a multi-byte table + * @table: Multi-byte table + * @index: Select this character + * @return: String pointer to the character + * + * Extract one multi-byte character from a string table. + * If the index is invalid, then a space character will be returned. + * If the character selected is '\n' (Ctrl-M), then "" will be returned. + */ +char *get_nth_wchar (mbchar_table *table, int index) +{ + if (!table || !table->chars || (index < 0) || (index >= table->len)) + return " "; + + if (table->chars[index][0] == '\n') + return ""; + + return table->chars[index]; +} + /* %a = address of author * %A = reply-to address (if present; otherwise: address of author * %b = filename of the originating folder @@ -420,7 +457,8 @@ hdr_format_str (char *dest, struct hdr_format_info *hfi = (struct hdr_format_info *) data; HEADER *hdr, *htmp; CONTEXT *ctx; - char fmt[SHORT_STRING], buf2[LONG_STRING], ch, *p; + char fmt[SHORT_STRING], buf2[LONG_STRING], *p; + char *wch; int do_locales, i; int optional = (flags & MUTT_FORMAT_OPTIONAL); int threads = ((Sort & SORT_MASK) == SORT_THREADS); @@ -915,26 +953,23 @@ hdr_format_str (char *dest, case 'S': if (hdr->deleted) - ch = 'D'; + wch = get_nth_wchar (Flagchars, FlagCharDeleted); else if (hdr->attach_del) - ch = 'd'; + wch = get_nth_wchar (Flagchars, FlagCharDeletedAttach); else if (hdr->tagged) - ch = '*'; + wch = get_nth_wchar (Flagchars, FlagCharTagged); else if (hdr->flagged) - ch = '!'; + wch = get_nth_wchar (Flagchars, FlagCharImportant); else if (hdr->replied) - ch = 'r'; + wch = get_nth_wchar (Flagchars, FlagCharReplied); else if (hdr->read && (ctx && ctx->msgnotreadyet != hdr->msgno)) - ch = '-'; + wch = get_nth_wchar (Flagchars, FlagCharSEmpty); else if (hdr->old) - ch = 'O'; + wch = get_nth_wchar (Flagchars, FlagCharOld); else - ch = 'N'; + wch = get_nth_wchar (Flagchars, FlagCharNew); - /* FOO - this is probably unsafe, but we are not likely to have such - a short string passed into this routine */ - buf2[0] = ch; - buf2[1] = 0; + snprintf (buf2, sizeof (buf2), "%s", wch); 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); @@ -1005,26 +1040,57 @@ hdr_format_str (char *dest, #endif case 'Z': - - ch = ' '; - - if (WithCrypto && hdr->security & GOODSIGN) - ch = 'S'; - else if (WithCrypto && hdr->security & ENCRYPT) - ch = 'P'; - else if (WithCrypto && hdr->security & SIGN) - ch = 's'; - else if ((WithCrypto & APPLICATION_PGP) && hdr->security & PGPKEY) - ch = 'K'; - - snprintf (buf2, sizeof (buf2), - "%c%c%s", (THREAD_NEW ? 'n' : (THREAD_OLD ? 'o' : - ((hdr->read && (ctx && ctx->msgnotreadyet != hdr->msgno)) - ? (hdr->replied ? 'r' : ' ') : (hdr->old ? 'O' : 'N')))), - hdr->deleted ? 'D' : (hdr->attach_del ? 'd' : ch), - hdr->tagged ? "*" : - (hdr->flagged ? "!" : - (Tochars && ((i = mutt_user_is_recipient (hdr)) < Tochars->len) ? Tochars->chars[i] : " "))); + { + /* New/Old for threads; replied; New/Old for messages */ + char *first; + if (THREAD_NEW) + first = get_nth_wchar (Flagchars, FlagCharNewThread); + else if (THREAD_OLD) + first = get_nth_wchar (Flagchars, FlagCharOldThread); + else if (hdr->read && (ctx && (ctx->msgnotreadyet != hdr->msgno))) + { + if (hdr->replied) + first = get_nth_wchar (Flagchars, FlagCharReplied); + else + first = get_nth_wchar (Flagchars, FlagCharZEmpty); + } + else + { + if (hdr->old) + first = get_nth_wchar (Flagchars, FlagCharOld); + else + first = get_nth_wchar (Flagchars, FlagCharNew); + } + + /* Marked for deletion; deleted attachments; crypto */ + char *second; + if (hdr->deleted) + second = get_nth_wchar (Flagchars, FlagCharDeleted); + else if (hdr->attach_del) + second = get_nth_wchar (Flagchars, FlagCharDeletedAttach); + else if (WithCrypto && (hdr->security & GOODSIGN)) + second = "S"; + else if (WithCrypto && (hdr->security & ENCRYPT)) + second = "P"; + else if (WithCrypto && (hdr->security & SIGN)) + second = "s"; + else if ((WithCrypto & APPLICATION_PGP) && (hdr->security & PGPKEY)) + second = "K"; + else + second = " "; + + /* Tagged, flagged and recipient flag */ + char *third; + if (hdr->tagged) + third = get_nth_wchar (Flagchars, FlagCharTagged); + else if (hdr->flagged) + third = get_nth_wchar (Flagchars, FlagCharImportant); + else + third = get_nth_wchar (Tochars, mutt_user_is_recipient (hdr)); + + snprintf (buf2, sizeof (buf2), "%s%s%s", first, second, third); + } + 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); diff --git a/init.h b/init.h index 2883bbdd8..7037b6e73 100644 --- a/init.h +++ b/init.h @@ -4015,6 +4015,25 @@ struct option_t MuttVars[] = { ** .dt 6 .dd L .dd Indicates the mail was sent to a mailing-list you subscribe to. ** .de */ + { "flag_chars", DT_MBCHARTBL, R_BOTH, UL &Flagchars, UL "*!DdrONon- " }, + /* + ** .pp + ** Controls the characters used in several flags. + ** .dl + ** .dt \fBCharacter\fP .dd \fBDefault\fP .dd \fBDescription\fP + ** .dt 1 .dd * .dd The mail is tagged. + ** .dt 2 .dd ! .dd The mail is flagged as important. + ** .dt 3 .dd D .dd The mail is marked for deletion. + ** .dt 4 .dd d .dd The mail has attachments marked for deletion. + ** .dt 5 .dd r .dd The mail has been replied to. + ** .dt 6 .dd O .dd The mail is Old (Unread but seen). + ** .dt 7 .dd N .dd The mail is New (Unread but not seen). + ** .dt 8 .dd o .dd The mail thread is Old (Unread but seen). + ** .dt 9 .dd n .dd The mail thread is New (Unread but not seen). + ** .dt 10 .dd - .dd The mail is read - %S expando. + ** .dt 11 .dd .dd The mail is read - %Z expando. + ** .de + */ { "trash", DT_PATH, R_NONE, UL &TrashPath, 0 }, /* ** .pp diff --git a/mutt.h b/mutt.h index f00b217be..6f4707b40 100644 --- a/mutt.h +++ b/mutt.h @@ -1109,7 +1109,8 @@ typedef struct /* multibyte character table. * Allows for direct access to the individual multibyte characters in a - * string. This is used for the Tochars and StChars option types. */ + * string. This is used for the Flagchars, Fromchars, StChars and Tochars + * option types. */ typedef struct { int len; /* number of characters */ -- 2.40.0