I'm attaching a slightly revised part1 patch, and adding another patch to the series. The first patch is changed so that the spacing can be invoked when pad=0. (There still might be a spacing issue for that case.)
The second patch fixes softpad when the pad character itself is multicolumn. -- 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 32730d6887919d5492f0d886dbdbd259eaa822d0 # 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 @@ -1301,26 +1301,34 @@ while (pad--) { memcpy (wptr, src, pl); wptr += pl; wlen += pl; col += pw; } } - else if (soft && pad < 0) + 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 937d8538258c624f716223be8cddbc7745712a89 # Parent 32730d6887919d5492f0d886dbdbd259eaa822d0 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,23 +1286,35 @@ { 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) { + /* 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; + /* Add pre-spacing to make multi-column pad characters and + * the contents after padding line up */ + else + { + while ((col + (pad * pw) + wid < COLS) && + (wlen + (pad * pl) + len < destlen)) + { + *wptr++ = ' '; + wlen++; + col++; + } + } while (pad--) { memcpy (wptr, src, pl); wptr += pl; wlen += pl; col += pw; } }
signature.asc
Description: PGP signature
