zsh-workers
 help / color / mirror / code / Atom feed
* Re: PROMPT escape sequences
       [not found]   ` <20071008042759.GA2413@primenet.com.au>
@ 2007-10-08 15:44     ` Bart Schaefer
  2007-10-09  3:23       ` Geoff Wing
  0 siblings, 1 reply; 5+ messages in thread
From: Bart Schaefer @ 2007-10-08 15:44 UTC (permalink / raw)
  To: zsh-workers

[moved to -workers]

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.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: PROMPT escape sequences
  2007-10-08 15:44     ` PROMPT escape sequences Bart Schaefer
@ 2007-10-09  3:23       ` Geoff Wing
  0 siblings, 0 replies; 5+ messages in thread
From: Geoff Wing @ 2007-10-09  3:23 UTC (permalink / raw)
  To: Zsh Hackers

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;


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Prompt escape sequences.
  1996-10-02 23:18 ` Zoltan Hidvegi
@ 1996-10-03  6:09   ` Richard Coleman
  0 siblings, 0 replies; 5+ messages in thread
From: Richard Coleman @ 1996-10-03  6:09 UTC (permalink / raw)
  To: Zoltan Hidvegi; +Cc: zsh-workers

> After looking at this patch I thought that a new point to the
> Util/zsh-development-guide might be useful.  I think that this should go
> under Etc.  Richard, why did you put it into Util when you created it?

I think I originally planned on adding some other developer oriented
things to Util, but never got back to that.

rc


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Prompt escape sequences.
  1996-10-01 17:11 Prompt " Louis Granboulan
@ 1996-10-02 23:18 ` Zoltan Hidvegi
  1996-10-03  6:09   ` Richard Coleman
  0 siblings, 1 reply; 5+ messages in thread
From: Zoltan Hidvegi @ 1996-10-02 23:18 UTC (permalink / raw)
  To: Louis Granboulan; +Cc: zsh-workers

> I wanted to add a new escape sequence %${varname} to print the
> content of a variable. Looking at putpromptchar, I found some
> bugs...

Thank you for the bugfix.  But I really do not see the usefullness of the
%${varnane} feature.  The same can be achieved using the promptsubst
option.  The %${...} syntax can create confusion since it is identical to
the parameter expansion syntax.

> print -P %-%7-
> 	outputs '%-%-' instead of '%-%7-'.
> 	I did not correct this behaviour.
> 	It may be easy to do.

I do not think it is a bug.  %% should always be used to put a % into the
prompt since future versions may introduce new % sequences.

After looking at this patch I thought that a new point to the
Util/zsh-development-guide might be useful.  I think that this should go
under Etc.  Richard, why did you put it into Util when you created it?


 6) Please try not using lines longer than 79 characters.  The coding style
    is Kernighan and Ritchie with 4 characters indentations.  This means
    that the opening brace is the last character in the line of the
    if/while/for/do statement and the closing brace has its own line:
 
        if (foo) {
 	   do that
        }
 
    Put only one command in a line (this also means that the body of an
    if/while/for/do statement has its own line with 4 characters indentation
    even if there are no braces).  Do not use space between the function
    name and the opening parenthesis.  Use space after if/for/while.  Use
    space after type casts.  Do not use (unsigned char) casts since some
    compilers do not handle them properly.  Use the provided STOUC(X) macro
    instead.
 
    If you use emacs 19.30 or newer you can put the following line to your
    ~/.emacs file to make these formatting rules the default:
 
    (add-hook 'c-mode-common-hook (function (lambda () (c-set-style "BSD"))))
 
    A global function declaration must look like this:
 
 /**/
 int
 foo(char *s, char **p)
 {
     function body
 }
 
     There must be an empty line, a line with /**/, a line with the type of
     the function and finally the name of the function with typed arguments.
     These lines should not be indented.  This rule is a must because the
     script generating function prototypes and the ansi2knr program depends
     on this format.

Zoltan


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Prompt escape sequences.
@ 1996-10-01 17:11 Louis Granboulan
  1996-10-02 23:18 ` Zoltan Hidvegi
  0 siblings, 1 reply; 5+ messages in thread
From: Louis Granboulan @ 1996-10-01 17:11 UTC (permalink / raw)
  To: zsh-workers

I wanted to add a new escape sequence %${varname} to print the
content of a variable. Looking at putpromptchar, I found some
bugs...

print -P %2147483648v
	does a segmentation fault because 2147483648 is translated
	to a negative number by zstrtol.
	The patch below corrects this bug.
print -P %-%7-
	outputs '%-%-' instead of '%-%7-'.
	I did not correct this behaviour.
	It may be easy to do.
print -P 'a\0b'
	outputs 'a', since \0 ends the string.
	"print 'a\0b'" does output a null character.
	I did not correct this behaviour.
	We may need to rewrite the whole function.


*** Src/zle_misc.c.orig	Tue Aug 13 22:24:14 1996
--- Src/zle_misc.c	Tue Oct  1 19:05:11 1996
***************
*** 859,865 ****
  putpromptchar(int doprint, int endchar)
  {
      char buf3[PATH_MAX], *ss;
!     int t0, arg, test, sep;
      struct tm *tm;
      time_t timet;
      Nameddir nd;
--- 859,866 ----
  putpromptchar(int doprint, int endchar)
  {
      char buf3[PATH_MAX], *ss;
!     int t0, test, sep;
!     unsigned int arg;
      struct tm *tm;
      time_t timet;
      Nameddir nd;
***************
*** 894,909 ****
  		case '.':
  		case '~':
  		    if ((nd = finddir(ss))) {
! 			arg--;
  			ss += strlen(nd->dir);
  		    }
  		case '/':
  		case 'C':
  		    for (; *ss; ss++)
  			if (*ss == '/')
! 			    arg--;
! 		    if (arg <= 0)
! 			test = 1;
  		    break;
  		case 't':
  		case 'T':
--- 895,909 ----
  		case '.':
  		case '~':
  		    if ((nd = finddir(ss))) {
! 			test++;
  			ss += strlen(nd->dir);
  		    }
  		case '/':
  		case 'C':
  		    for (; *ss; ss++)
  			if (*ss == '/')
! 			    test++;
! 		    test = (arg <= test);
  		    break;
  		case 't':
  		case 'T':
***************
*** 1230,1235 ****
--- 1230,1262 ----
  		addbufspc(1);
  		*bp++ = (geteuid())? '%' : '#';
  		break;
+ 	    case '$':
+ 		if (fm[1] != '{') {
+ 		    *bp++ = '%';
+ 		    *bp++ = '$';
+ 		    break;
+ 		}
+ 		else {
+ 		    char **array, *variable, endname;
+ 		    fm++; variable = fm+1;
+                     while (*fm && *fm != '}') fm++;
+                     /* We don't need to allocate something for the var name */
+                     endname = *fm;
+                     *fm = NULL;
+                     if (arg) {
+ 		        array = getaparam(variable);
+ 		        variable = NULL;
+                         if ( array && (arrlen(array) >= arg) )
+ 		            variable = array[arg-1];
+                     }
+                     else
+ 		      variable = getsparam(variable);
+ 		    stradd(variable ? variable : "");
+                     *fm = endname;
+ 		}
+ 		if(!*fm)
+ 		    return 0;
+ 		break;
  	    case 'v':
  		if (!arg)
  		    arg = 1;
***************
*** 1241,1247 ****
  		break;
  	    case '_':
  		if (cmdsp) {
! 		    if (arg > cmdsp || arg <= 0)
  			arg = cmdsp;
  		    for (t0 = cmdsp - arg; arg--; t0++) {
  			stradd(cmdnames[cmdstack[t0]]);
--- 1268,1274 ----
  		break;
  	    case '_':
  		if (cmdsp) {
! 		    if (arg > cmdsp || !arg)
  			arg = cmdsp;
  		    for (t0 = cmdsp - arg; arg--; t0++) {
  			stradd(cmdnames[cmdstack[t0]]);
*** Doc/zshparam.man.orig	Tue Aug 13 22:24:13 1996
--- Doc/zshparam.man	Tue Oct  1 19:05:08 1996
***************
*** 579,584 ****
--- 579,589 ----
  The value of the first element of the $psvar array parameter.  Following
  the '%' with an integer gives that element of the array.
  .TP
+ .B %${\fIvarname\fB}
+ The value of the variable $varname.
+ Following the '%' with an integer gives that element of the array.
+ Using the $psvar array is faster.
+ .TP
  \fB%{\fP...\fB%}\fP
  Include a string as a literal escape sequence.
  The string within the braces should not change the cursor
*** Doc/zsh.texi.orig	Thu Aug 15 18:47:39 1996
--- Doc/zsh.texi	Tue Oct  1 19:09:00 1996
***************
*** 4144,4149 ****
--- 4144,4154 ----
  Following the @code{%} with an integer gives that element of the
  array.
  
+ @item %$@{@var{varname}@}
+ The value of the variable @code{varname}.
+ Following the @code{%} with an integer gives that element of the array.
+ Using the $psvar array is faster.
+ 
  @item %@{@dots{}%@}
  Include a string as a literal escape sequence.  The string within the
  braces should not change the cursor position.


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2007-10-09  3:23 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20071008034223.GA789@primenet.com.au>
     [not found] ` <071007210217.ZM24374@torch.brasslantern.com>
     [not found]   ` <20071008042759.GA2413@primenet.com.au>
2007-10-08 15:44     ` PROMPT escape sequences Bart Schaefer
2007-10-09  3:23       ` Geoff Wing
1996-10-01 17:11 Prompt " Louis Granboulan
1996-10-02 23:18 ` Zoltan Hidvegi
1996-10-03  6:09   ` Richard Coleman

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).