zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.w.stephenson@ntlworld.com>
To: zsh-workers@zsh.org
Subject: Re: zsh/complist colours improperly handle multibyte characters
Date: Sun, 23 Oct 2016 18:30:48 +0100	[thread overview]
Message-ID: <20161023183048.3b6d21bb@ntlworld.com> (raw)
In-Reply-To: <161020210735.ZM6446@torch.brasslantern.com>

On Thu, 20 Oct 2016 21:07:35 -0700
Bart Schaefer <schaefer@brasslantern.com> wrote:
> The problem with the (#b) example is not that the pattern has matched
> improperly, but that #ifdef MULTIBYTE_SUPPORT has never been worked
> into complist.c:clprintfmt().  So it is counting the bytes rather than
> the display width when deciding where to start/stop coloring.

So something like this might be better?

This is counting characters properly, but not taking into account the
width of the character may be greater than 1.  As the outer loop is
assuming one position per character I don't know how to fix that
properly.  Probably incrementing cc by the width and doing something
clever with the "beg =" is a further imporvement, but I have no idea
what to about i.

pws

diff --git a/Src/Zle/complist.c b/Src/Zle/complist.c
index 8aeb6c3..39ac782 100644
--- a/Src/Zle/complist.c
+++ b/Src/Zle/complist.c
@@ -662,7 +662,9 @@ clprintfmt(char *p, int ml)
 
     initiscol();
 
-    for (; *p; p++) {
+    while (*p) {
+	convchar_t chr;
+	int chrlen = MB_METACHARLENCONV(p, &chr);
 	doiscol(i++);
 	cc++;
 	if (*p == '\n') {
@@ -673,11 +675,16 @@ clprintfmt(char *p, int ml)
 	if (ml == mlend - 1 && (cc % zterm_columns) == zterm_columns - 1)
 	    return 0;
 
-	if (*p == Meta) {
+	while (chrlen) {
+	    if (*p == Meta) {
+		p++;
+		chrlen--;
+		putc(*p ^ 32, shout);
+	    } else
+		putc(*p, shout);
+	    chrlen--;
 	    p++;
-	    putc(*p ^ 32, shout);
-	} else
-	    putc(*p, shout);
+	}
 	if ((beg = !(cc % zterm_columns)))
 	    ml++;
 	if (mscroll && !(cc % zterm_columns) &&


  reply	other threads:[~2016-10-23 17:36 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20161021011017eucas1p1d1fceae920242e69b4426bc41cb3c064@eucas1p1.samsung.com>
2016-10-21  1:09 ` Danielle McLean
2016-10-21  4:07   ` Bart Schaefer
2016-10-23 17:30     ` Peter Stephenson [this message]
2016-10-23 18:23       ` Bart Schaefer
     [not found]     ` <20161023184641.4549e10a@ntlworld.com>
     [not found]       ` <161023105652.ZM3309@torch.brasslantern.com>
2016-10-23 18:59         ` Peter Stephenson
2016-10-23 19:34           ` Bart Schaefer
2016-10-25 10:44             ` Peter Stephenson
2016-10-25 15:59               ` Bart Schaefer
2016-10-25 16:05                 ` Peter Stephenson
2016-10-21  8:33   ` Peter Stephenson
2016-10-21 15:48     ` Bart Schaefer

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=20161023183048.3b6d21bb@ntlworld.com \
    --to=p.w.stephenson@ntlworld.com \
    --cc=zsh-workers@zsh.org \
    /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).