changeset: 7082:b4d0bb558636
user:      Kevin McCarthy <ke...@8t8.us>
date:      Fri Jun 09 11:31:05 2017 -0700
link:      http://dev.mutt.org/hg/mutt/rev/b4d0bb558636

Change the compose menu fields to be dynamically padded.

Pad based on the maximum width of the fields.  Note that this is a bit
of a mess, because some of the fields are translated while others are
not.

changeset: 7083:dd0208f13983
user:      Consus <con...@gmx.com>
date:      Fri Jun 09 11:31:06 2017 -0700
link:      http://dev.mutt.org/hg/mutt/rev/dd0208f13983

Rename 'sign as' to 'Sign as'; makes compose menu more consistent.

diffs (152 lines):

diff -r 966f08249216 -r dd0208f13983 compose.c
--- a/compose.c Thu Jun 08 13:26:35 2017 -0700
+++ b/compose.c Fri Jun 09 11:31:06 2017 -0700
@@ -70,9 +70,11 @@
   HDR_ATTACH  = (HDR_FCC + 5) /* where to start printing the attachments */
 };
 
-#define HDR_XOFFSET 10
-#define TITLE_FMT "%10s" /* Used for Prompts, which are ASCII */
-#define W (MuttIndexWindow->cols - HDR_XOFFSET)
+int HeaderPadding[HDR_CRYPTINFO + 1] = {0};
+int MaxHeaderWidth = 0;
+
+#define HDR_XOFFSET MaxHeaderWidth
+#define W (MuttIndexWindow->cols - MaxHeaderWidth)
 
 static const char * const Prompts[] =
 {
@@ -97,6 +99,56 @@
   { NULL,      0 }
 };
 
+static void calc_header_width_padding (int idx, const char *header, int 
calc_max)
+{
+  int width;
+
+  HeaderPadding[idx] = mutt_strlen (header);
+  width = mutt_strwidth (header);
+  if (calc_max && MaxHeaderWidth < width)
+    MaxHeaderWidth = width;
+  HeaderPadding[idx] -= width;
+}
+
+
+/* The padding needed for each header is strlen() + max_width - strwidth().
+ *
+ * calc_header_width_padding sets each entry in HeaderPadding to
+ * strlen - width.  Then, afterwards, we go through and add max_width
+ * to each entry.
+ */
+static void init_header_padding (void)
+{
+  static short done = 0;
+  int i;
+
+  if (done)
+    return;
+  done = 1;
+
+  for (i = 0; i <= HDR_FCC; i++)
+    calc_header_width_padding (i, Prompts[i], 1);
+
+#ifdef MIXMASTER
+  calc_header_width_padding (HDR_MIX,  _("Mix: "), 1);
+#endif
+
+  /* TODO: mark for translation */
+  calc_header_width_padding (HDR_CRYPT, "Security: ", 1);
+
+  /* L10N:
+   * This string is used by the compose menu.  It is suggested that it not
+   * be wider than 20 character cells, if possible. */
+  calc_header_width_padding (HDR_CRYPTINFO, _("Sign as: "), 0);
+
+  for (i = 0; i <= HDR_CRYPTINFO; i++)
+  {
+    HeaderPadding[i] += MaxHeaderWidth;
+    if (HeaderPadding[i] < 0)
+      HeaderPadding[i] = 0;
+  }
+}
+
 static void snd_entry (char *b, size_t blen, MUTTMENU *menu, int num)
 {
   mutt_FormatString (b, blen, 0, MuttIndexWindow->cols, NONULL (AttachFormat), 
mutt_attach_fmt,
@@ -111,7 +163,8 @@
 static void redraw_crypt_lines (HEADER *msg)
 {
   SETCOLOR (MT_COLOR_COMPOSE_HEADER);
-  mutt_window_mvprintw (MuttIndexWindow, HDR_CRYPT, 0, TITLE_FMT, "Security: 
");
+  mutt_window_mvprintw (MuttIndexWindow, HDR_CRYPT, 0,
+                        "%*s", HeaderPadding[HDR_CRYPT], "Security: ");
   NORMAL_COLOR;
 
   if ((WithCrypto & (APPLICATION_PGP | APPLICATION_SMIME)) == 0)
@@ -167,7 +220,7 @@
       && (msg->security & APPLICATION_PGP) && (msg->security & SIGN))
   {
     SETCOLOR (MT_COLOR_COMPOSE_HEADER);
-    printw (TITLE_FMT, _("sign as: "));
+    printw ("%*s", HeaderPadding[HDR_CRYPTINFO], _("Sign as: "));
     NORMAL_COLOR;
     printw ("%s", PgpSignAs ? PgpSignAs : _("<default>"));
   }
@@ -176,7 +229,7 @@
       && (msg->security & APPLICATION_SMIME) && (msg->security & SIGN))
   {
     SETCOLOR (MT_COLOR_COMPOSE_HEADER);
-    printw (TITLE_FMT, _("sign as: "));
+    printw ("%*s", HeaderPadding[HDR_CRYPTINFO], _("Sign as: "));
     NORMAL_COLOR;
     printw ("%s", SmimeDefaultKey ? SmimeDefaultKey : _("<default>"));
   }
@@ -203,8 +256,9 @@
   char *t;
 
   SETCOLOR (MT_COLOR_COMPOSE_HEADER);
+  mutt_window_mvprintw (MuttIndexWindow, HDR_MIX, 0,
   /* L10N: "Mix" refers to the MixMaster chain for anonymous email */
-  mutt_window_mvprintw (MuttIndexWindow, HDR_MIX, 0, TITLE_FMT, _("Mix: "));
+                        "%*s", HeaderPadding[HDR_MIX], _("Mix: "));
   NORMAL_COLOR;
 
   if (!chain)
@@ -273,7 +327,8 @@
   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]);
+  mutt_window_mvprintw (MuttIndexWindow, line, 0,
+                        "%*s", HeaderPadding[line], Prompts[line]);
   NORMAL_COLOR;
   mutt_paddstr (W, buf);
 }
@@ -286,14 +341,16 @@
   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]);
+  mutt_window_mvprintw (MuttIndexWindow, HDR_SUBJECT, 0,
+                        "%*s", HeaderPadding[HDR_SUBJECT], 
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]);
+  mutt_window_mvprintw (MuttIndexWindow, HDR_FCC, 0,
+                        "%*s", HeaderPadding[HDR_FCC], Prompts[HDR_FCC]);
   NORMAL_COLOR;
   mutt_paddstr (W, fcc);
 
@@ -585,6 +642,8 @@
   struct stat st;
   compose_redraw_data_t rd;
 
+  init_header_padding ();
+
   rd.msg = msg;
   rd.fcc = fcc;
 

Reply via email to