On Wed, Apr 13, 2016 at 10:12:19AM -0700, Kevin J. McCarthy wrote: > Actually, thank you, yourx point made me notice I need to fix the while > loop just below: > > - while (pad--) > + while (pad-- > 0)
Reposting the patches with this and the right-align pad=0 change, just to keep it clear. -- Kevin J. McCarthy GPG Fingerprint: 8975 A9B3 3AA3 7910 385C 5308 ADEF 7684 8031 6BDA http://www.8t8.us/configs/gpg-key-transition-statement.txt
# HG changeset patch # User Kevin McCarthy <[email protected]> # Date 1460489595 25200 # Tue Apr 12 12:33:15 2016 -0700 # Node ID 8e7e8b6490c8e6e8d978304d05b337cd9f996261 # Parent eb94f64ad81ad19f223af8e86aefe414f5ce185a Add spacing to truncated multi-column characters when using soft-fill. First, fix the left-hand side column truncation calculation: "col + pad*pw -offset" pad = (COLS - col - wid) / pw, so this becomes "col + COLS - col - wid - offset" => "COLS - wid - offset" The problem is that pad was calculated *before* the right side was mutt_wstr_trunc() truncated, which may adjust wid! We want that calculation, with correct values, so instead just use the final reduction directly. (Note, the reduction ignores integer truncation, but pad shouldn't be used here in any case, because it's negative: there is no padding occuring). Second, when the left-hand side is truncated, multi-column characters may get chopped in the middle. Truncated characters are not included in the wlen and col values returned. Add spaces until the number of columns lines up (checking to make sure we don't run out of space too). diff --git a/muttlib.c b/muttlib.c --- a/muttlib.c +++ b/muttlib.c @@ -1309,18 +1309,26 @@ else if (soft && pad < 0) { int offset = ((flags & M_FORMAT_ARROWCURSOR) && option (OPTARROWCURSOR)) ? 3 : 0; /* \0-terminate dest for length computation in mutt_wstr_trunc() */ *wptr = 0; /* make sure right part is at most as wide as display */ len = mutt_wstr_trunc (buf, destlen, COLS-offset, &wid); /* truncate left so that right part fits completely in */ - wlen = mutt_wstr_trunc (dest, destlen - len, col + pad*pw -offset, &col); + wlen = mutt_wstr_trunc (dest, destlen - len, COLS - wid - offset, &col); wptr = dest + wlen; + /* Multi-column characters may be truncated in the middle. + * Add spacing so the right hand side lines up. */ + while ((col + wid < COLS - offset) && (wlen + len < destlen)) + { + *wptr++ = ' '; + wlen++; + col++; + } } if (len + wlen > destlen) len = mutt_wstr_trunc (buf, destlen - wlen, COLS - col, NULL); memcpy (wptr, buf, len); wptr += len; wlen += len; col += wid; src += pl;
# HG changeset patch # User Kevin McCarthy <[email protected]> # Date 1460489637 25200 # Tue Apr 12 12:33:57 2016 -0700 # Node ID d10b045f81647128ba766f1718d64fa9024e1852 # Parent 8e7e8b6490c8e6e8d978304d05b337cd9f996261 Pre-space softfill multi-column padding. 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. diff --git a/muttlib.c b/muttlib.c --- a/muttlib.c +++ b/muttlib.c @@ -1286,24 +1286,36 @@ { int pad; /* get contents after padding */ mutt_FormatString (buf, sizeof (buf), 0, src + pl, callback, data, flags); 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; wlen += pl; col += pw; } } else if (soft && pad < 0)
signature.asc
Description: PGP signature
