Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Broken completion with UTF-8 description



On Sun, 17 Sep 2006 18:53:50 +0400
Andrey Borzenkov <arvidjaar@xxxxxxxxxx> 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@xxxxxxxxxxxx>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/



Messages sorted by: Reverse Date, Date, Thread, Author