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).
/* 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);