From: Kevin McCarthy Date: Fri, 9 Jun 2017 18:31:05 +0000 (-0700) Subject: Change the compose menu fields to be dynamically padded. X-Git-Tag: neomutt-20170707^2^2~17 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=fe6c2382f14daee3c63fae2d12c9952b3b70b68a;p=neomutt 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. --- diff --git a/compose.c b/compose.c index 386e33004..b3de55783 100644 --- a/compose.c +++ b/compose.c @@ -70,9 +70,11 @@ enum 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,57 @@ static const struct mapping_t ComposeHelp[] = { { 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); + + /* TODO: convert to "Sign as: " */ + /* 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 +164,8 @@ static void snd_entry (char *b, size_t blen, MUTTMENU *menu, int num) 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 +221,7 @@ static void redraw_crypt_lines (HEADER *msg) && (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 : _("")); } @@ -176,7 +230,7 @@ static void redraw_crypt_lines (HEADER *msg) && (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 : _("")); } @@ -203,8 +257,9 @@ static void redraw_mix_line (LIST *chain) 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 +328,8 @@ static void draw_envelope_addr (int line, ADDRESS *addr) 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 +342,16 @@ static void draw_envelope (HEADER *msg, char *fcc) 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 +643,8 @@ int mutt_compose_menu (HEADER *msg, /* structure for new message */ struct stat st; compose_redraw_data_t rd; + init_header_padding (); + rd.msg = msg; rd.fcc = fcc;