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

PATCH (RFC): Parse argument to %F and %K as prompt sequences



You can't quote any } inside this argument, but I can't imagine when
you'd need to, it's only intended to be used as %F{%3v}. If the code
doesn't offend anyone horribly, it should probably be put in a helper
function, but I didn't want to bother before I asked if anyone can see
any problems with doing this. It does change behaviour as
% print -P %F{red1blue}
no longer outputs 1blue} in red, but that was a questionable feature
I think. print -P %F{red1blue does still work as before though :).

---
 Src/prompt.c |   34 ++++++++++++++++++++++++++++------
 1 file changed, 28 insertions(+), 6 deletions(-)

diff --git a/Src/prompt.c b/Src/prompt.c
index e51ce24..c87df54 100644
--- a/Src/prompt.c
+++ b/Src/prompt.c
@@ -495,10 +495,21 @@ putpromptchar(int doprint, int endchar, unsigned int *txtchangep)
 		break;
 	    case 'F':
 		if (bv->fm[1] == '{') {
+		    char *ep;
 		    bv->fm += 2;
-		    arg = match_colour((const char **)&bv->fm, 1, 0);
-		    if (*bv->fm != '}')
-			bv->fm--;
+		    if ((ep = strchr(bv->fm, '}'))) {
+			char oc = *ep, *col, *coll;
+			*ep = '\0';
+			coll = col = promptexpand(bv->fm, 0, NULL, NULL, NULL);
+			*ep = oc;
+			arg = match_colour((const char **)&coll, 1, 0);
+			free(col);
+			bv->fm = ep;
+		    } else {
+			arg = match_colour((const char **)&bv->fm, 1, 0);
+			if (*bv->fm != '}')
+			    bv->fm--;
+		    }
 		} else
 		    arg = match_colour(NULL, 1, arg);
 		if (arg >= 0 && !(arg & TXTNOFGCOLOUR)) {
@@ -516,10 +527,21 @@ putpromptchar(int doprint, int endchar, unsigned int *txtchangep)
 		break;
 	    case 'K':
 		if (bv->fm[1] == '{') {
+		    char *ep;
 		    bv->fm += 2;
-		    arg = match_colour((const char **)&bv->fm, 0, 0);
-		    if (*bv->fm != '}')
-			bv->fm--;
+		    if ((ep = strchr(bv->fm, '}'))) {
+			char oc = *ep, *col, *coll;
+			*ep = '\0';
+			coll = col = promptexpand(bv->fm, 0, NULL, NULL, NULL);
+			*ep = oc;
+			arg = match_colour((const char **)&coll, 1, 0);
+			free(col);
+			bv->fm = ep;
+		    } else {
+			arg = match_colour((const char **)&bv->fm, 1, 0);
+			if (*bv->fm != '}')
+			    bv->fm--;
+		    }
 		} else
 		    arg = match_colour(NULL, 0, arg);
 		if (arg >= 0 && !(arg & TXTNOBGCOLOUR)) {
-- 
1.7.10.GIT



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