Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
PATCH (RFC): Parse argument to %F and %K as prompt sequences
- X-seq: zsh-workers 30471
- From: Mikael Magnusson <mikachu@xxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: PATCH (RFC): Parse argument to %F and %K as prompt sequences
- Date: Thu, 3 May 2012 21:00:02 +0200
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:subject:date:message-id:x-mailer; bh=oLSTqkpv54wLnROCOtMd0sjCPxgl7LWQYFZMnfdswbk=; b=rMfqVpIwP8XjrfMqee6rqfTaEkkqhMRNzKOedQ42dmyNEnObtsSp018VKl7xReKGpS 0I/7EhQZICBZJXWOwWDxh3U8HUQwON8k+GMKByoh4hZ0KCQYJ3sxNaoGvRn1Y2GAVR3P UMDh71kwY4tZzD14qmSqxHTqfU8B26W8mO2ZuFmWtDTdzxbHehzm0BtAUH3LUxGVWCfg NxVYcjsFQ+DHj0QqBTeR50AKx9Bhx4QR9BvoqWE4IFy8dtFRdLyT2O6NSx7V+mWiyDg6 TPhmNYALtYnantHzT5/q6cchKlNgjeLGSCc2YDclx/xJATbuX4QE9gaMbhMnU6j4md8m c1pw==
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
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