zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.w.stephenson@ntlworld.com>
To: zsh-workers@sunsite.dk
Subject: Re: PATCH: displaying wide characters
Date: Fri, 21 Oct 2005 23:29:49 +0100	[thread overview]
Message-ID: <200510212229.j9LMTnku022669@pwslaptop.csr.com> (raw)
In-Reply-To: Your message of "Fri, 21 Oct 2005 14:39:42 -0000." <1051021143942.ZM7464@candle.brasslantern.com>

Bart Schaefer wrote:
> }           If the string is longer than the  specified  truncation
> }           length,  it  will  appear in full, completely replacing
> }           the truncated string.
> } 
> } which is unambiguous, so I presume there is a bug in the old code.
> 
> Either that or an intentional change that failed to make it into the
> documentation.  The prompt truncation code was completely rewritten a
> while back (prior to 4.0, so *quite* a while back).

I'll assume the manual page is still correct.  I don't remember any
 ^   suggestion of a change.
 |
 Look! ASCII apostrophes!

This change makes the whole thing much more maintainable...
I've also removed a few TODOs which no longer apply.

Index: Src/prompt.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/prompt.c,v
retrieving revision 1.28
diff -u -r1.28 prompt.c
--- Src/prompt.c	19 Oct 2005 21:59:36 -0000	1.28
+++ Src/prompt.c	21 Oct 2005 22:23:18 -0000
@@ -1038,18 +1038,18 @@
 	     * Note that if the truncation string is longer than the
 	     * truncation length (twidth > truncwidth), the truncation
 	     * string is used in full.
-	     *
-	     * TODO: we don't take account of multibyte characters
-	     * in the string we're truncating.
 	     */
 	    char *t = truncstr;
 	    int fullen = bp - ptr;
 	    int twidth, maxwidth;
-#ifdef ZLE_UNICODE_SUPPORT
 	    int ntrunc = strlen(t);
 
+#ifdef ZLE_UNICODE_SUPPORT
 	    /* Use screen width of string */
 	    twidth = mb_width(t);
+#else
+	    twidth = ztrlen(t);
+#endif
 	    if (twidth < truncwidth) {
 		maxwidth = truncwidth - twidth;
 		/*
@@ -1110,6 +1110,7 @@
 				fulltextptr++;
 			    }
 			} else {
+#ifdef ZLE_UNICODE_SUPPORT
 			    /*
 			     * Normal text: build up a multibyte character.
 			     */
@@ -1143,6 +1144,13 @@
 				    remw -= wcwidth(cc);
 				}
 			    }
+#else
+			    /* Single byte character */
+			    if (*fulltextptr == Meta)
+				fulltextptr++;
+			    fulltextptr++;
+			    remw--;
+#endif
 			}
 		    }
 
@@ -1170,6 +1178,7 @@
 			    for (; *skiptext != Outpar && *skiptext;
 				 skiptext++);
 			} else {
+#ifdef ZLE_UNICODE_SUPPORT
 			    char inchar;
 			    wchar_t cc;
 			    int ret;
@@ -1194,6 +1203,12 @@
 				    maxwidth -= wcwidth(cc);
 				}
 			    }
+#else
+			    if (*skiptext == Meta)
+				skiptext++;
+			    skiptext++;
+			    maxwidth--;
+#endif
 			}
 		    }
 		    /*
@@ -1240,96 +1255,6 @@
 		bp = ptr;
 	    }
 	    *bp = '\0';
-#else
-	    twidth = ztrlen(t);
-	    maxwidth = twidth < truncwidth ? truncwidth - twidth : 0;
-	    if (w < fullen) {
-		/* Invisible substrings, lots of shuffling. */
-		int n = strlen(t);
-		char *p = ptr, *q = buf;
-		addbufspc(n);
-		ptr = buf + (p - q); /* addbufspc() may have realloc()'d */
-
-		if (truncatleft) {
-		    p = ptr + n;
-		    q = p;
-
-		    /*
-		     * I don't think we need n and the test below since
-		     * we must have enough space (we are using a subset
-		     * of the existing text with no repetition) and the
-		     * string is null-terminated, so I haven't copied it
-		     * to the ZLE_UNICODE_SUPPORT section.
-		     */
-		    n = fullen - w;
-
-		    /* Shift the whole string right, then *
-		     * selectively copy to the left.      */
-		    memmove(p, ptr, fullen);
-		    while (w > 0 || n > 0) {
-			if (*p == Inpar)
-			    do {
-				*q++ = *p;
-				--n;
-			    } while (*p++ != Outpar && *p && n);
-			else if (w) {
-			    if (--w < maxwidth)
-				*q++ = *p;
-			    ++p;
-			}
-		    }
-		    bp = q;
-		} else {
-		    /* Truncate on the right, selectively */
-		    q = ptr + fullen;
-
-		    /* First skip over as much as will "fit". */
-		    while (w > 0 && maxwidth > 0) {
-			if (*ptr == Inpar)
-			    while (*ptr++ != Outpar && *ptr) {;}
-			else
-			    ++ptr, --w, --maxwidth;
-		    }
-		    if (ptr < q) {
-			/* We didn't reach the end of the string. *
-			 * In case there are more invisible bits, *
-			 * insert the truncstr and keep looking.  */
-			memmove(ptr + n, ptr, q - ptr);
-			q = ptr + n;
-			while (*t)
-			    *ptr++ = *t++;
-			while (*q) {
-			    if (*q == Inpar)
-				do {
-				    *ptr++ = *q;
-				} while (*q++ != Outpar && *q);
-			    else
-				++q;
-			}
-			bp = ptr;
-			*bp = 0;
-		    } else
-			bp = ptr + n;
-		}
-	    } else {
-		/* No invisible substrings. */
-		if (twidth > fullen) {
-		    addbufspc(twidth - fullen);
-		    ptr = bp;	/* addbufspc() may have realloc()'d buf */
-		    bp += twidth - fullen;
-		} else
-		    bp -= fullen - truncwidth;
-		if (truncatleft) {
-		    if (maxwidth)
-			memmove(ptr + strlen(t), ptr + fullen - maxwidth,
-				maxwidth);
-		} else
-		    ptr += maxwidth;
-	    }
-	    /* Finally, copy the truncstr into place. */
-	    while (*t)
-		*ptr++ = *t++;
-#endif
 	}
 	zsfree(truncstr);
 	truncwidth = 0;
Index: Src/Zle/zle_refresh.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/zle_refresh.c,v
retrieving revision 1.31
diff -u -r1.31 zle_refresh.c
--- Src/Zle/zle_refresh.c	19 Oct 2005 23:45:06 -0000	1.31
+++ Src/Zle/zle_refresh.c	21 Oct 2005 22:23:19 -0000
@@ -413,11 +413,7 @@
     rpms->sen = rpms->s + winw;
 }
 
-/*
- * TODO currently it assumes sceenwidth 1 for every character
- * (except for characters in the prompt which are correctly handled
- * by wcwidth()).
- */
+
 /**/
 mod_export void
 zrefresh(void)

-- 
Peter Stephenson <p.w.stephenson@ntlworld.com>
Web page still at http://www.pwstephenson.fsnet.co.uk/


  reply	other threads:[~2005-10-21 22:36 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-10-19 20:31 Peter Stephenson
2005-10-19 20:41 ` Peter Stephenson
2005-10-20  0:39   ` Mikael Magnusson
2005-10-20  9:39     ` Peter Stephenson
2005-10-20 15:02       ` Bart Schaefer
2005-10-21  9:03         ` Peter Stephenson
2005-10-21 14:39           ` Bart Schaefer
2005-10-21 22:29             ` Peter Stephenson [this message]
2005-10-24  8:40       ` Mikael Magnusson
2005-10-24  9:07         ` Peter Stephenson
2005-10-24 12:41           ` Mikael Magnusson
2005-10-24 12:47             ` Peter Stephenson
2005-10-24 16:53               ` Peter Stephenson
2005-10-25 23:11         ` Peter Stephenson
2005-10-26  5:19           ` Mikael Magnusson
2005-10-26  9:17             ` Peter Stephenson
2005-10-26 14:31               ` Mikael Magnusson
2005-10-28 12:03                 ` Peter Stephenson
2005-10-28 17:19                   ` Mikael Magnusson
2005-10-19 22:47 ` Peter Stephenson

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=200510212229.j9LMTnku022669@pwslaptop.csr.com \
    --to=p.w.stephenson@ntlworld.com \
    --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).