<<< Date Index >>>     <<< Thread Index >>>

Re: mutt/1503: Help-Text on UTF-8 Terminals



The following reply was made to PR mutt/1503; it has been noted by GNATS.

From: TAKIZAWA Takashi <taki@xxxxxxxxxxxxxxxx>
To: bug-any@xxxxxxxxxxxxx
Cc: 
Subject: Re: mutt/1503: Help-Text on UTF-8 Terminals
Date: Thu, 15 Mar 2007 02:59:10 +0900

 --VbJkn9YxBvnuCH5J
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: inline
 
 I'm sorry. 
 The previous patch functions partial.
 The attached patch fixes the rest of problem.
 
 On Tue, Mar 13, 2007 at 09:32:37PM +0100,
  Christoph Berg wrote:
 
 > **** Comment added by cb on Tue, 13 Mar 2007 21:32:37 +0100 ****
 >  It's still broken. Again using a silly macro to test:
 > 
 > Wide terminal:
 > t                      M tag-thread                      ????????????a 
 > ????????????????????????a ??????????????????????
 > 
 > Smaller terminal:
 > t                  M tag-thread                  ????????????a ???????????
 >                                                  ?????????????a 
 > ??????????????????????
 > 
 > It broke the middle word in two parts.
 > 
 > 
 
 -- 
 TAKIZAWA Takashi
 http://www.emaillab.org/
 
 
 --VbJkn9YxBvnuCH5J
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: attachment; filename="patch-1.5.14.tt.help-wrap-width.1"
 
 diff -r 99d92c8219f4 help.c
 --- a/help.c   Tue Mar 13 22:41:34 2007 -0700
 +++ b/help.c   Thu Mar 15 02:41:33 2007 +0900
 @@ -147,6 +147,38 @@ static int print_macro (FILE *f, int max
    return (maxwidth - n);
  }
  
 +static int get_wrapped_width (const char *t, size_t wid)
 +{
 +  wchar_t wc;
 +  size_t k;
 +  size_t m, n;
 +  size_t len = mutt_strlen (t);
 +  const char *s = t;
 +  mbstate_t mbstate;
 +
 +  memset (&mbstate, 0, sizeof (mbstate));
 +  for (m = wid, n = 0;
 +       len && (k = mbrtowc (&wc, s, len, &mbstate)) && (n <= wid);
 +       s += k, len -= k)
 +  {
 +    if (*s == ' ')
 +      m = n;
 +    if (k == (size_t)(-1) || k == (size_t)(-2))
 +    {
 +      k = (k == (size_t)(-1)) ? 1 : len;
 +      wc = replacement_char ();
 +    }
 +    if (!IsWPrint (wc))
 +      wc = '?';
 +    n += wcwidth (wc);
 +  }
 +  if (n > wid)
 +    n = m;
 +  else
 +    n = wid;
 +  return n;
 +}
 +
  static int pad (FILE *f, int col, int i)
  {
    char fmt[8];
 @@ -221,15 +253,7 @@ static void format_line (FILE *f, int is
        if (ismacro >= 0)
        {
        SKIPWS(t3);
 -
 -      /* FIXME: this is completely wrong */
 -      if ((n = mutt_strwidth (t3)) > COLS - col)
 -      {
 -        n = COLS - col;
 -        for (col_a = n; col_a > 0 && t3[col_a] != ' '; col_a--) ;
 -        if (col_a)
 -          n = col_a;
 -      }
 +      n = get_wrapped_width (t3, n);
        }
  
        print_macro (f, n, &t3);
 
 --VbJkn9YxBvnuCH5J--