zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.w.stephenson@ntlworld.com>
To: Andrey Borzenkov <arvidjaar@newmail.ru>
Cc: zsh-workers@sunsite.dk
Subject: Re: Broken completion with UTF-8 description
Date: Sun, 17 Sep 2006 20:16:12 +0100	[thread overview]
Message-ID: <20060917201612.fe9933d5.p.w.stephenson@ntlworld.com> (raw)
In-Reply-To: <200609171853.57050.arvidjaar@newmail.ru>

On Sun, 17 Sep 2006 18:53:50 +0400
Andrey Borzenkov <arvidjaar@newmail.ru> wrote:
> Writing completion for kcmshell (attached); it outputs list of KDE 
> configuration modules together with descriptions and I have not found
> any way (confirmed by KDE developers) to force descriptions in
> English. So far I get the following:
> 
> ...
> printers                       -- Настройки системы печа�[0m
> privacy                        -- Модуль kcontrol, очищающ�[0m
> profilechooser                 -- Mandriva KDE profilechooser
> proxy                          -- Настройка серверов прок�[0m
> ...

That's another evening of my life gone.

Something in computil was using strlen() to decide whether to truncate
at the end of the screen line.  Apparently descriptions never wrap.

There are lots of other strlen()s in computil, but they don't seem to be
used for anything like this.

Index: Src/Zle/computil.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/computil.c,v
retrieving revision 1.94
diff -u -r1.94 computil.c
--- Src/Zle/computil.c	30 May 2006 22:35:04 -0000	1.94
+++ Src/Zle/computil.c	17 Sep 2006 19:11:04 -0000
@@ -616,8 +616,22 @@
                     memset(buf, ' ', cd_state.pre);
                     memcpy(buf, str->str, str->len);
                     strcpy(sufp, str->desc);
-                    if (strlen(buf) >= columns - 1)
-                        buf[columns - 1] = '\0';
+                    if (MB_METASTRWIDTH(buf) >= columns - 1) {
+			char *termptr = buf;
+			int w;
+			MB_METACHARINIT();
+			for (w = columns - 1; *termptr && w > 0; ) {
+			    convchar_t cchar;
+			    int cw;
+			    termptr += MB_METACHARLENCONV(termptr, &cchar);
+			    cw = WCWIDTH(cchar);
+			    if (cw >= 0)
+				w -= cw;
+			    else
+				w--;
+			}
+                        *termptr = '\0';
+		    }
                     *dp++ = ztrdup(buf);
                 }
                 *mp = *dp = NULL;

-- 
Peter Stephenson <p.w.stephenson@ntlworld.com>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/


  reply	other threads:[~2006-09-17 19:16 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-09-17 14:53 Andrey Borzenkov
2006-09-17 19:16 ` Peter Stephenson [this message]
2006-09-21 17:04   ` PATCH: " Andrey Borzenkov
2006-09-21 17:22     ` Peter Stephenson
2006-09-21 17:44       ` Andrey Borzenkov
2006-10-07  7:58       ` Andrey Borzenkov
2006-09-21 20:02     ` Peter Stephenson
2006-09-23  7:05       ` Andrey Borzenkov
2006-09-23  7:36         ` Andrey Borzenkov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20060917201612.fe9933d5.p.w.stephenson@ntlworld.com \
    --to=p.w.stephenson@ntlworld.com \
    --cc=arvidjaar@newmail.ru \
    --cc=zsh-workers@sunsite.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).