]> granicus.if.org Git - neomutt/commitdiff
Pre-space softfill multi-column padding.
authorKevin McCarthy <kevin@8t8.us>
Thu, 14 Apr 2016 19:35:50 +0000 (12:35 -0700)
committerKevin McCarthy <kevin@8t8.us>
Thu, 14 Apr 2016 19:35:50 +0000 (12:35 -0700)
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

index 382be6e4aa72a060a6bf7870d845eab257490fee..309f1bfeda41973b447f92720d0cd04c0806ea40 100644 (file)
--- 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;