zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.w.stephenson@ntlworld.com>
To: "Zsh Hackers' List" <zsh-workers@sunsite.dk>
Subject: Re: Phil's prompt is not working when LANG is set to UTF-8
Date: Sun, 17 Feb 2008 17:40:20 +0000	[thread overview]
Message-ID: <200802171740.m1HHeKas008113@pws-pc.ntlworld.com> (raw)
In-Reply-To: Message from Peter Stephenson <p.w.stephenson@ntlworld.com> of "Sun, 17 Feb 2008 16:43:18 GMT." <20080217164318.29e922a3@pws-pc>

Peter Stephenson wrote:
> > Does it matter where %G appears?  %{...%7G...%} ?
> 
> Because they're indepdendent, it doesn't matter at all

Slight overstatement, since if we truncate the prompt the position of
the %G becomes important if it's not associated with the right
%{...%}, but the answer to the spirit of your original question is still
no, it doesn't matter where it appears within a %{...%}.

However, this, er, prompted me to look and see how we handle truncation
and there is code missing for this case.  The right thing to do must be
to copy the entire group, since we don't know how to divide it up.
Consequently it's a good idea to divide the groups as far as possible
into single characters.  This seems worth documenting.  This is an
updated patch.

Index: Doc/Zsh/prompt.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/prompt.yo,v
retrieving revision 1.10
diff -u -r1.10 prompt.yo
--- Doc/Zsh/prompt.yo	15 Feb 2008 23:59:09 -0000	1.10
+++ Doc/Zsh/prompt.yo	17 Feb 2008 17:39:39 -0000
@@ -187,6 +187,9 @@
 Include a string as a literal escape sequence.
 The string within the braces should not change the cursor
 position.  Brace pairs can nest.
+
+A positive numeric argument between the tt(%) and the %%({) is treated as
+described for tt(%G) below.
 )
 item(tt(%G))(
 Within a tt(%{)...tt(%}) sequence, include a `glitch': that is, assume
@@ -199,6 +202,13 @@
 indicates a character width other than one.  Hence tt(%{)var(seq)tt(%2G%})
 outputs var(seq) and assumes it takes up the width of two standard
 characters.
+
+Multiple uses of tt(%G) accumulate in the obvious fashion; the position
+of the tt(%G) is unimportant.  Negative integers are not handled.
+
+Note that when prompt truncation is in use it is advisable to divide up
+output into single characters within each tt(%{)...tt(%}) group so that
+the correct truncation point can be found.
 )
 enditem()
 
Index: Src/prompt.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/prompt.c,v
retrieving revision 1.45
diff -u -r1.45 prompt.c
--- Src/prompt.c	15 Feb 2008 23:59:09 -0000	1.45
+++ Src/prompt.c	17 Feb 2008 17:39:41 -0000
@@ -472,7 +472,10 @@
 		    addbufspc(1);
 		    *bp++ = Inpar;
 		}
-		break;
+		if (arg <= 0)
+		    break;
+		/* else */
+		/* FALLTHROUGH */
 	    case 'G':
 		if (arg > 0) {
 		    addbufspc(arg);
@@ -948,9 +951,11 @@
 		break;
 	    case MB_INVALID:
 		memset(&mbs, 0, sizeof mbs);
-		/* FALL THROUGH */
+		/* Invalid character: assume single width. */
+		multi = 0;
+		w++;
+		break;
 	    case 0:
-		/* Invalid character or null: assume no output. */
 		multi = 0;
 		break;
 	    default:
@@ -1124,14 +1129,19 @@
 			    /*
 			     * Text marked as invisible: copy
 			     * regardless, since we don't know what
-			     * this does but it shouldn't affect
-			     * the width.
+			     * this does.  It only affects the width
+			     * if there are Nularg's present.
+			     * However, even in that case we
+			     * can't break the sequence down, so
+			     * we still loop over the entire group.
 			     */
 			    for (;;) {
 				*ptr++ = *fulltextptr;
 				if (*fulltextptr == Outpar ||
 				    *fulltextptr == '\0')
 				    break;
+				if (*fulltextptr == Nularg)
+				    remw--;
 				fulltextptr++;
 			    }
 			} else {
@@ -1206,8 +1216,15 @@
 
 		    while (maxwidth > 0 && *skiptext) {
 			if (*skiptext == Inpar) {
-			    for (; *skiptext != Outpar && *skiptext;
-				 skiptext++);
+			    /* see comment on left truncation above */
+			    for (;;) {
+				if (*skiptext == Outpar ||
+				    *skiptext == '\0')
+				    break;
+				if (*skiptext == Nularg)
+				    maxwidth--;
+				skiptext++;
+			    }
 			} else {
 #ifdef MULTIBYTE_SUPPORT
 			    char inchar;


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


  reply	other threads:[~2008-02-17 17:42 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-02-15 23:52 Fw: " Peter Stephenson
2008-02-16  7:56 ` Andrey Borzenkov
2008-02-16  8:50   ` Wael Nasreddine
2008-02-16  9:00   ` Bart Schaefer
2008-02-16 19:13 ` Bart Schaefer
2008-02-16 19:32   ` Bart Schaefer
2008-02-17 16:43   ` Peter Stephenson
2008-02-17 17:40     ` Peter Stephenson [this message]
     [not found] <20080211033116.GD19613@phoenix.nasreddine.info>
     [not found] ` <20080214123757.GA2943@phoenix.nasreddine.info>
     [not found]   ` <200802141300.m1ED0qOo017425@news01.csr.com>
2008-02-15 19:48     ` Andrey Borzenkov
2008-02-15 19:55       ` Andrey Borzenkov
2008-02-15 20:10       ` Wael Nasreddine

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=200802171740.m1HHeKas008113@pws-pc.ntlworld.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).