changeset: 7032:a6db4750f675
user:      Kevin McCarthy <ke...@8t8.us>
date:      Wed May 03 18:52:54 2017 -0700
link:      http://dev.mutt.org/hg/mutt/rev/a6db4750f675

Add color commands for the compose menu headers and security status. (closes 
#3915).

Add "color compose header" to color the From/To/Subject/etc fields in
the compose menu.

Add "color compose security_encrypt/sign/both/none" to color the
security status of the message.

diffs (288 lines):

diff -r 7e1edf6a7ed7 -r a6db4750f675 color.c
--- a/color.c   Sun Apr 30 15:56:15 2017 -0700
+++ b/color.c   Wed May 03 18:52:54 2017 -0700
@@ -106,6 +106,16 @@
   { NULL,              0 }
 };
 
+static const struct mapping_t ComposeFields[] =
+{
+  { "header",               MT_COLOR_COMPOSE_HEADER },
+  { "security_encrypt",     MT_COLOR_COMPOSE_SECURITY_ENCRYPT },
+  { "security_sign",        MT_COLOR_COMPOSE_SECURITY_SIGN },
+  { "security_both",        MT_COLOR_COMPOSE_SECURITY_BOTH },
+  { "security_none",        MT_COLOR_COMPOSE_SECURITY_NONE },
+  { NULL,                   0 }
+};
+
 #define COLOR_QUOTE_INIT       8
 
 static COLOR_LINE *mutt_new_color_line (void)
@@ -622,6 +632,22 @@
     
     *o = MT_COLOR_QUOTED;
   }
+  else if (!ascii_strcasecmp(buf->data, "compose"))
+  {
+    if (!MoreArgs(s))
+    {
+      strfcpy(err->data, _("Missing arguments."), err->dsize);
+      return -1;
+    }
+
+    mutt_extract_token(buf, s, 0);
+
+    if ((*o = mutt_getvaluebyname (buf->data, ComposeFields)) == -1)
+    {
+      snprintf (err->data, err->dsize, _("%s: no such object"), buf->data);
+      return (-1);
+    }
+  }
   else if ((*o = mutt_getvaluebyname (buf->data, Fields)) == -1)
   {
     snprintf (err->data, err->dsize, _("%s: no such object"), buf->data);
diff -r 7e1edf6a7ed7 -r a6db4750f675 compose.c
--- a/compose.c Sun Apr 30 15:56:15 2017 -0700
+++ b/compose.c Wed May 03 18:52:54 2017 -0700
@@ -110,7 +110,9 @@
 
 static void redraw_crypt_lines (HEADER *msg)
 {
+  SETCOLOR (MT_COLOR_COMPOSE_HEADER);
   mutt_window_mvprintw (MuttIndexWindow, HDR_CRYPT, 0, TITLE_FMT, "Security: 
");
+  NORMAL_COLOR;
 
   if ((WithCrypto & (APPLICATION_PGP | APPLICATION_SMIME)) == 0)
   {
@@ -119,13 +121,26 @@
   }
 
   if ((msg->security & (ENCRYPT | SIGN)) == (ENCRYPT | SIGN))
+  {
+    SETCOLOR (MT_COLOR_COMPOSE_SECURITY_BOTH);
     addstr (_("Sign, Encrypt"));
+  }
   else if (msg->security & ENCRYPT)
+  {
+    SETCOLOR (MT_COLOR_COMPOSE_SECURITY_ENCRYPT);
     addstr (_("Encrypt"));
+  }
   else if (msg->security & SIGN)
+  {
+    SETCOLOR (MT_COLOR_COMPOSE_SECURITY_SIGN);
     addstr (_("Sign"));
+  }
   else
+  {
+    SETCOLOR (MT_COLOR_COMPOSE_SECURITY_NONE);
     addstr (_("None"));
+  }
+  NORMAL_COLOR;
 
   if ((msg->security & (ENCRYPT | SIGN)))
   {
@@ -150,20 +165,32 @@
 
   if ((WithCrypto & APPLICATION_PGP)
       && (msg->security & APPLICATION_PGP) && (msg->security & SIGN))
-    printw (TITLE_FMT "%s", _("sign as: "), PgpSignAs ? PgpSignAs : 
_("<default>"));
+  {
+    SETCOLOR (MT_COLOR_COMPOSE_HEADER);
+    printw (TITLE_FMT, _("sign as: "));
+    NORMAL_COLOR;
+    printw ("%s", PgpSignAs ? PgpSignAs : _("<default>"));
+  }
 
   if ((WithCrypto & APPLICATION_SMIME)
-      && (msg->security & APPLICATION_SMIME) && (msg->security & SIGN)) {
-      printw (TITLE_FMT "%s", _("sign as: "), SmimeDefaultKey ? 
SmimeDefaultKey : _("<default>"));
+      && (msg->security & APPLICATION_SMIME) && (msg->security & SIGN))
+  {
+    SETCOLOR (MT_COLOR_COMPOSE_HEADER);
+    printw (TITLE_FMT, _("sign as: "));
+    NORMAL_COLOR;
+    printw ("%s", SmimeDefaultKey ? SmimeDefaultKey : _("<default>"));
   }
 
   if ((WithCrypto & APPLICATION_SMIME)
       && (msg->security & APPLICATION_SMIME)
       && (msg->security & ENCRYPT)
       && SmimeCryptAlg
-      && *SmimeCryptAlg) {
-    mutt_window_mvprintw (MuttIndexWindow, HDR_CRYPTINFO, 40, "%s%s", 
_("Encrypt with: "),
-               NONULL(SmimeCryptAlg));
+      && *SmimeCryptAlg)
+  {
+    SETCOLOR (MT_COLOR_COMPOSE_HEADER);
+    mutt_window_mvprintw (MuttIndexWindow, HDR_CRYPTINFO, 40, "%s", _("Encrypt 
with: "));
+    NORMAL_COLOR;
+    printw ("%s", NONULL(SmimeCryptAlg));
   }
 }
 
@@ -175,8 +202,10 @@
   int c;
   char *t;
 
+  SETCOLOR (MT_COLOR_COMPOSE_HEADER);
   /* L10N: "Mix" refers to the MixMaster chain for anonymous email */
   mutt_window_mvprintw (MuttIndexWindow, HDR_MIX, 0, TITLE_FMT, _("Mix: "));
+  NORMAL_COLOR;
 
   if (!chain)
   {
@@ -243,7 +272,9 @@
 
   buf[0] = 0;
   rfc822_write_address (buf, sizeof (buf), addr, 1);
+  SETCOLOR (MT_COLOR_COMPOSE_HEADER);
   mutt_window_mvprintw (MuttIndexWindow, line, 0, TITLE_FMT, Prompts[line]);
+  NORMAL_COLOR;
   mutt_paddstr (W, buf);
 }
 
@@ -253,10 +284,17 @@
   draw_envelope_addr (HDR_TO, msg->env->to);
   draw_envelope_addr (HDR_CC, msg->env->cc);
   draw_envelope_addr (HDR_BCC, msg->env->bcc);
+
+  SETCOLOR (MT_COLOR_COMPOSE_HEADER);
   mutt_window_mvprintw (MuttIndexWindow, HDR_SUBJECT, 0, TITLE_FMT, 
Prompts[HDR_SUBJECT]);
+  NORMAL_COLOR;
   mutt_paddstr (W, NONULL (msg->env->subject));
+
   draw_envelope_addr (HDR_REPLYTO, msg->env->reply_to);
+
+  SETCOLOR (MT_COLOR_COMPOSE_HEADER);
   mutt_window_mvprintw (MuttIndexWindow, HDR_FCC, 0, TITLE_FMT, 
Prompts[HDR_FCC]);
+  NORMAL_COLOR;
   mutt_paddstr (W, fcc);
 
   if (WithCrypto)
diff -r 7e1edf6a7ed7 -r a6db4750f675 doc/manual.xml.head
--- a/doc/manual.xml.head       Sun Apr 30 15:56:15 2017 -0700
+++ b/doc/manual.xml.head       Wed May 03 18:52:54 2017 -0700
@@ -2664,6 +2664,20 @@
 <replaceable class="parameter">pattern</replaceable>
 </arg>
 
+<command>color</command>
+<arg choice="plain">
+<option>compose</option>
+</arg>
+<arg choice="plain">
+<replaceable class="parameter">composeobject</replaceable>
+</arg>
+<arg choice="plain">
+<replaceable class="parameter">foreground</replaceable>
+</arg>
+<arg choice="plain">
+<replaceable class="parameter">background</replaceable>
+</arg>
+
 <command>uncolor</command>
 <group choice="req">
 <arg choice="plain">
@@ -2728,6 +2742,18 @@
 </itemizedlist>
 
 <para>
+<emphasis>composeobject</emphasis> can be one of:
+</para>
+
+<itemizedlist>
+<listitem><para>header</para></listitem>
+<listitem><para>security_encrypt</para></listitem>
+<listitem><para>security_sign</para></listitem>
+<listitem><para>security_both</para></listitem>
+<listitem><para>security_none</para></listitem>
+</itemizedlist>
+
+<para>
 <emphasis>foreground</emphasis> and <emphasis>background</emphasis> can
 be one of the following:
 </para>
@@ -2841,6 +2867,17 @@
 <replaceable class="parameter">pattern</replaceable>
 </arg>
 
+<command>mono</command>
+<arg choice="plain">
+<option>compose</option>
+</arg>
+<arg choice="plain">
+<replaceable class="parameter">composeobject</replaceable>
+</arg>
+<arg choice="plain">
+<replaceable class="parameter">attribute</replaceable>
+</arg>
+
 <command>unmono</command>
 <group choice="req">
 <arg choice="plain">
@@ -2864,8 +2901,9 @@
 </cmdsynopsis>
 
 <para>
-For <emphasis>object</emphasis>, see the <command>color</command>
-command. <emphasis>attribute</emphasis> can be one of the following:
+For <emphasis>object</emphasis> and <emphasis>composeobject</emphasis>,
+see the <command>color</command> command. <emphasis>attribute</emphasis>
+can be one of the following:
 </para>
 
 <itemizedlist>
@@ -9502,6 +9540,20 @@
 <replaceable class="parameter">pattern</replaceable>
 </arg>
 
+<command><link linkend="color">color</link></command>
+<arg choice="plain">
+<option>compose</option>
+</arg>
+<arg choice="plain">
+<replaceable class="parameter">composeobject</replaceable>
+</arg>
+<arg choice="plain">
+<replaceable class="parameter">foreground</replaceable>
+</arg>
+<arg choice="plain">
+<replaceable class="parameter">background</replaceable>
+</arg>
+
 <command><link linkend="color">uncolor</link></command>
 <group choice="req">
 <arg choice="plain">
@@ -9845,6 +9897,17 @@
 <replaceable class="parameter">pattern</replaceable>
 </arg>
 
+<command><link linkend="mono">mono</link></command>
+<arg choice="plain">
+<option>compose</option>
+</arg>
+<arg choice="plain">
+<replaceable class="parameter">composeobject</replaceable>
+</arg>
+<arg choice="plain">
+<replaceable class="parameter">attribute</replaceable>
+</arg>
+
 <command><link linkend="mono">unmono</link></command>
 <group choice="req">
 <arg choice="plain">
diff -r 7e1edf6a7ed7 -r a6db4750f675 mutt_curses.h
--- a/mutt_curses.h     Sun Apr 30 15:56:15 2017 -0700
+++ b/mutt_curses.h     Wed May 03 18:52:54 2017 -0700
@@ -132,6 +132,11 @@
   MT_COLOR_SB_INDICATOR,
   MT_COLOR_SB_SPOOLFILE,
 #endif
+  MT_COLOR_COMPOSE_HEADER,
+  MT_COLOR_COMPOSE_SECURITY_ENCRYPT,
+  MT_COLOR_COMPOSE_SECURITY_SIGN,
+  MT_COLOR_COMPOSE_SECURITY_BOTH,
+  MT_COLOR_COMPOSE_SECURITY_NONE,
   MT_COLOR_MAX
 };
 

Reply via email to