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

Re: PROMPT escape sequences



On Tuesday 2007-10-09 01:45 +1000, Bart Schaefer output:
:On Oct 8,  2:27pm, Geoff Wing wrote:
:} :PS1='very%Blong%bstring%#%S '
:} :The %S effect begins at the %B, not at the point where it should.
:} OK, well, it was broken between 4.2.0 and 4.2.1.
:} Quick surface check and I'd say it looks like zle_refresh.c:1.13
:That seems unlikely; there's only a two-line diff in there, and the first
:of those lines is "if (trashedzle)".
:zsh-workers/20149 may have been the culprit, but I don't see anything
:else from around July 2004 that meddles with prompts.

I don't use anything that needs to reexpand the prompt in-place, so I'm not
entirely sure this covers all that is needed.

Regards,
Geoff

--- Src/Zle/zle_main.c.org	2007-10-09 11:56:26.000000000 +1000
+++ Src/Zle/zle_main.c	2007-10-09 13:00:22.000000000 +1000
@@ -1678,8 +1678,10 @@ reexpandprompt(void)
     if (!reexpanding++) {
 	free(lpromptbuf);
 	lpromptbuf = promptexpand(raw_lp ? *raw_lp : NULL, 1, NULL, NULL);
+	pmpt_attr = txtchange;
 	free(rpromptbuf);
 	rpromptbuf = promptexpand(raw_rp ? *raw_rp : NULL, 1, NULL, NULL);
+	rpmpt_attr = txtchange;
     }
     reexpanding--;
 }
--- Src/Zle/zle_refresh.c.org	2007-10-09 11:56:26.000000000 +1000
+++ Src/Zle/zle_refresh.c	2007-10-09 13:11:04.000000000 +1000
@@ -413,6 +413,23 @@ snextline(Rparams rpms)
     rpms->sen = rpms->s + winw;
 }
 
+/**/
+static void
+settextattributes(void)
+{
+    if (txtchangeisset(TXTNOBOLDFACE))
+	tsetcap(TCALLATTRSOFF, 0);
+    if (txtchangeisset(TXTNOSTANDOUT))
+	tsetcap(TCSTANDOUTEND, 0);
+    if (txtchangeisset(TXTNOUNDERLINE))
+	tsetcap(TCUNDERLINEEND, 0);
+    if (txtchangeisset(TXTBOLDFACE))
+	tsetcap(TCBOLDFACEBEG, 0);
+    if (txtchangeisset(TXTSTANDOUT))
+	tsetcap(TCSTANDOUTBEG, 0);
+    if (txtchangeisset(TXTUNDERLINE))
+	tsetcap(TCUNDERLINEBEG, 0);
+}
 
 /**/
 mod_export void
@@ -429,11 +446,9 @@ zrefresh(void)
     int tmpcs, tmpll;		/* ditto cursor position and line length     */
     int tmpalloced;		/* flag to free tmpline when finished        */
     int remetafy;		/* flag that zle line is metafied            */
+    int fixprompt;		/* we still need to reexpand the prompt      */
     struct rparams rpms;
     
-    if (trashedzle)
-	reexpandprompt();
-
     /* If this is called from listmatches() (indirectly via trashzle()), and *
      * that was called from the end of zrefresh(), then we don't need to do  *
      * anything.  All this `inlist' code is actually unnecessary, but it     *
@@ -525,6 +540,7 @@ zrefresh(void)
 	    listshown = 0;
 	}
 #endif
+	fixprompt = trashedzle;
 	resetvideo();
 	resetneeded = 0;	/* unset */
 	oput_rpmpt = 0;		/* no right-prompt currently on screen */
@@ -533,6 +549,8 @@ zrefresh(void)
 	tsetcap(TCALLATTRSOFF, 0);
 	tsetcap(TCSTANDOUTEND, 0);
 	tsetcap(TCUNDERLINEEND, 0);
+	/* cheat on attribute unset */
+	txtunset(TXTBOLDFACE|TXTSTANDOUT|TXTUNDERLINE|TXTDIRTY);
 
         if (!clearflag) {
             if (tccan(TCCLEAREOD))
@@ -544,26 +562,17 @@ zrefresh(void)
 	}
         if (t0 > -1)
             olnct = (t0 < winh) ? t0 : winh;
+	if (fixprompt)
+	    reexpandprompt(); 
         if (termflags & TERM_SHORT)
             vcs = 0;
-        else if (!clearflag && lpromptbuf[0]) {
+	else if (!clearflag && lpromptbuf[0]) {
             zputs(lpromptbuf, shout);
 	    if (lpromptwof == winw)
 		zputs("\n", shout);	/* works with both hasam and !hasam */
 	} else {
 	    txtchange = pmpt_attr;
-	    if (txtchangeisset(TXTNOBOLDFACE))
-		tsetcap(TCALLATTRSOFF, 0);
-	    if (txtchangeisset(TXTNOSTANDOUT))
-		tsetcap(TCSTANDOUTEND, 0);
-	    if (txtchangeisset(TXTNOUNDERLINE))
-		tsetcap(TCUNDERLINEEND, 0);
-	    if (txtchangeisset(TXTBOLDFACE))
-		tsetcap(TCBOLDFACEBEG, 0);
-	    if (txtchangeisset(TXTSTANDOUT))
-		tsetcap(TCSTANDOUTBEG, 0);
-	    if (txtchangeisset(TXTUNDERLINE))
-		tsetcap(TCUNDERLINEBEG, 0);
+	    settextattributes();
 	}
 	if (clearflag) {
 	    zputc(ZWC('\r'));
@@ -872,20 +881,8 @@ individually */
 
 /* reset character attributes */
     if (clearf && postedit) {
-	if ((txtchange = pmpt_attr ? pmpt_attr : rpmpt_attr)) {
-	    if (txtchangeisset(TXTNOBOLDFACE))
-		tsetcap(TCALLATTRSOFF, 0);
-	    if (txtchangeisset(TXTNOSTANDOUT))
-		tsetcap(TCSTANDOUTEND, 0);
-	    if (txtchangeisset(TXTNOUNDERLINE))
-		tsetcap(TCUNDERLINEEND, 0);
-	    if (txtchangeisset(TXTBOLDFACE))
-		tsetcap(TCBOLDFACEBEG, 0);
-	    if (txtchangeisset(TXTSTANDOUT))
-		tsetcap(TCSTANDOUTBEG, 0);
-	    if (txtchangeisset(TXTUNDERLINE))
-		tsetcap(TCUNDERLINEBEG, 0);
-	}
+	if ((txtchange = pmpt_attr ? pmpt_attr : rpmpt_attr))
+	    settextattributes();
     }
     clearf = 0;
     oput_rpmpt = put_rpmpt;



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