changeset: 6620:fef5b5ed0f44 user: Kevin McCarthy <[email protected]> date: Thu Apr 14 12:35:48 2016 -0700 link: http://dev.mutt.org/hg/mutt/rev/fef5b5ed0f44
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). changeset: 6621:92bbc02fdf9c user: Kevin McCarthy <[email protected]> date: Thu Apr 14 12:35:50 2016 -0700 link: http://dev.mutt.org/hg/mutt/rev/92bbc02fdf9c 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. changeset: 6622:ca1af57e1855 user: Kevin McCarthy <[email protected]> date: Thu Apr 14 12:35:53 2016 -0700 link: http://dev.mutt.org/hg/mutt/rev/ca1af57e1855 Fix right justify buffer-truncated pad calculation in mutt_FormatString() Vincent Lefèvre noted that the computation had implementation defined behavior and was potentially incorrect. Change to make sure the subtraction won't lead to a wrap-around, and set pad to 0 in that case. changeset: 6623:9a9c515e09d3 user: Kevin McCarthy <[email protected]> date: Thu Apr 14 12:35:57 2016 -0700 link: http://dev.mutt.org/hg/mutt/rev/9a9c515e09d3 Fix soft-padding available columns computation. If arrow_cursor is set, it's possible that COLS < offset. Compute avail_cols, floored at 0, and use that instead. diffs (61 lines): diff -r eb94f64ad81a -r 9a9c515e09d3 muttlib.c --- a/muttlib.c Mon Apr 11 12:45:25 2016 -0700 +++ b/muttlib.c Thu Apr 14 12:35:57 2016 -0700 @@ -1291,14 +1291,26 @@ 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 = (destlen > wlen + len) ? ((destlen - wlen - len) / pl) : 0; + 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; @@ -1309,13 +1321,22 @@ else if (soft && pad < 0) { int offset = ((flags & M_FORMAT_ARROWCURSOR) && option (OPTARROWCURSOR)) ? 3 : 0; + int avail_cols = (COLS > offset) ? (COLS - offset) : 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); + len = mutt_wstr_trunc (buf, destlen, avail_cols, &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, avail_cols - wid, &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 < avail_cols) && (wlen + len < destlen)) + { + *wptr++ = ' '; + wlen++; + col++; + } } if (len + wlen > destlen) len = mutt_wstr_trunc (buf, destlen - wlen, COLS - col, NULL);
