From: Mikael Magnusson <mikachu@gmail.com>
To: zsh-workers@zsh.org
Subject: PATCH (RFC): Parse argument to %F and %K as prompt sequences
Date: Thu, 3 May 2012 21:00:02 +0200 [thread overview]
Message-ID: <1336071602-31699-1-git-send-email-mikachu@gmail.com> (raw)
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
next reply other threads:[~2012-05-03 19:00 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-05-03 19:00 Mikael Magnusson [this message]
2012-05-31 19:56 ` PATCH: " Mikael Magnusson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1336071602-31699-1-git-send-email-mikachu@gmail.com \
--to=mikachu@gmail.com \
--cc=zsh-workers@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).