On Thu, Apr 14, 2016 at 09:06:34AM +0200, Vincent Lefevre wrote:
> You could write it:
> 
>   if (wlen + (pad * pl) + len > destlen)
>     pad = wlen + len > destlen ? 0 : (destlen - wlen - len) / pl;
>   else
> 
> to avoid the not so readable nested if's.

Thanks Vincent, I'll break this patch out separately, to help keep the
purpose of each patch distinct.

After some testing, I also noticed that with $arrow_cursor and the
terminal squished down, it's possible for COLS < offset, so I'll add a
fourth patch.  Again, I'll keep this separate just so the progression is
clear.

diff --git a/muttlib.c b/muttlib.c
--- a/muttlib.c
+++ b/muttlib.c
@@ -1316,26 +1316,27 @@
              wptr += pl;
              wlen += pl;
              col += pw;
            }
          }
          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, COLS - wid - 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 < COLS - offset) && (wlen + len < destlen))
+            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);




-- 
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

Attachment: signature.asc
Description: PGP signature

Reply via email to