From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23866 invoked from network); 17 Feb 2008 17:42:08 -0000 X-Spam-Checker-Version: SpamAssassin 3.2.4 (2008-01-01) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.2.4 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 17 Feb 2008 17:42:08 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 73995 invoked from network); 17 Feb 2008 17:42:00 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 17 Feb 2008 17:42:00 -0000 Received: (qmail 24146 invoked by alias); 17 Feb 2008 17:41:57 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 24566 Received: (qmail 24132 invoked from network); 17 Feb 2008 17:41:57 -0000 Received: from bifrost.dotsrc.org (130.225.254.106) by sunsite.dk with SMTP; 17 Feb 2008 17:41:57 -0000 Received: from mtaout03-winn.ispmail.ntl.com (mtaout03-winn.ispmail.ntl.com [81.103.221.49]) by bifrost.dotsrc.org (Postfix) with ESMTP id 302C78026E0B for ; Sun, 17 Feb 2008 18:41:52 +0100 (CET) Received: from aamtaout03-winn.ispmail.ntl.com ([81.103.221.35]) by mtaout03-winn.ispmail.ntl.com with ESMTP id <20080217174416.MSPD19530.mtaout03-winn.ispmail.ntl.com@aamtaout03-winn.ispmail.ntl.com> for ; Sun, 17 Feb 2008 17:44:16 +0000 Received: from pws-pc.ntlworld.com ([81.107.42.63]) by aamtaout03-winn.ispmail.ntl.com with ESMTP id <20080217174558.LNFD26699.aamtaout03-winn.ispmail.ntl.com@pws-pc.ntlworld.com> for ; Sun, 17 Feb 2008 17:45:58 +0000 Received: from pws-pc (pws-pc [127.0.0.1]) by pws-pc.ntlworld.com (8.14.2/8.14.2) with ESMTP id m1HHeKas008113 for ; Sun, 17 Feb 2008 17:40:20 GMT Message-Id: <200802171740.m1HHeKas008113@pws-pc.ntlworld.com> From: Peter Stephenson To: "Zsh Hackers' List" Subject: Re: Phil's prompt is not working when LANG is set to UTF-8 In-Reply-To: Message from Peter Stephenson of "Sun, 17 Feb 2008 16:43:18 GMT." <20080217164318.29e922a3@pws-pc> Date: Sun, 17 Feb 2008 17:40:20 +0000 X-Cloudmark-Analysis: v=1.0 c=1 a=Rw7lO6RaNG4A:15 a=8Gg2pG7T7twA:10 a=3FTp5y5X6ml6ZCsPBftHHg==:17 a=NLZqzBF-AAAA:8 a=uw3Z9MFpSnCRk7WDWDMA:9 a=Tg2k1d2OrrHB66K-PvAA:7 a=tsKynhFq_z6_7HDzNk8ETYn7CbEA:4 a=_dQi-Dcv4p4A:10 a=rCbS6JjwtmAA:10 X-Virus-Scanned: ClamAV 0.91.2/5849/Sun Feb 17 18:11:14 2008 on bifrost X-Virus-Status: Clean 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 Web page now at http://homepage.ntlworld.com/p.w.stephenson/