From 88a81b9491f9cb838fa5ae8a5bfd54f3e2670fb7 Mon Sep 17 00:00:00 2001 From: Kevin McCarthy Date: Thu, 14 Apr 2016 12:35:50 -0700 Subject: [PATCH] Pre-space softfill multi-column padding. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Similar to the previous patch, this deals with multi-column padding characters and soft-fill. This will add spacing so the padding and content after padding aligns with the right side. You can see the effect by setting set index_format="%s %*我[ooooo]" and resizing the terminal. The right hand side will be jagged without the patch. --- muttlib.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/muttlib.c b/muttlib.c index 382be6e4..309f1bfe 100644 --- a/muttlib.c +++ b/muttlib.c @@ -1291,14 +1291,26 @@ void mutt_FormatString (char *dest, /* output buffer */ len = mutt_strlen (buf); wid = mutt_strwidth (buf); - /* try to consume as many columns as we can, if we don't have - * memory for that, use as much memory as possible */ pad = (COLS - col - wid) / pw; - if (pad > 0 && wlen + (pad * pl) + len > destlen) - pad = ((signed)(destlen - wlen - len)) / pl; - if (pad > 0) + if (pad >= 0) { - while (pad--) + /* try to consume as many columns as we can, if we don't have + * memory for that, use as much memory as possible */ + if (wlen + (pad * pl) + len > destlen) + pad = ((signed)(destlen - wlen - len)) / pl; + else + { + /* Add pre-spacing to make multi-column pad characters and + * the contents after padding line up */ + while ((col + (pad * pw) + wid < COLS) && + (wlen + (pad * pl) + len < destlen)) + { + *wptr++ = ' '; + wlen++; + col++; + } + } + while (pad-- > 0) { memcpy (wptr, src, pl); wptr += pl; -- 2.40.0