* PATCH (RFC): Parse argument to %F and %K as prompt sequences
@ 2012-05-03 19:00 Mikael Magnusson
2012-05-31 19:56 ` PATCH: " Mikael Magnusson
0 siblings, 1 reply; 2+ messages in thread
From: Mikael Magnusson @ 2012-05-03 19:00 UTC (permalink / raw)
To: zsh-workers
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
^ permalink raw reply [flat|nested] 2+ messages in thread
* PATCH: Parse argument to %F and %K as prompt sequences
2012-05-03 19:00 PATCH (RFC): Parse argument to %F and %K as prompt sequences Mikael Magnusson
@ 2012-05-31 19:56 ` Mikael Magnusson
0 siblings, 0 replies; 2+ messages in thread
From: Mikael Magnusson @ 2012-05-31 19:56 UTC (permalink / raw)
To: zsh-workers
Well, nobody objected so here's a version with de-duplicated code. The
previous patch broke %K, but it works now (passed 1 for is_fg on both
paths).
---
Src/prompt.c | 43 +++++++++++++++++++++++++++++--------------
1 file changed, 29 insertions(+), 14 deletions(-)
diff --git a/Src/prompt.c b/Src/prompt.c
index e51ce24..95a7d49 100644
--- a/Src/prompt.c
+++ b/Src/prompt.c
@@ -232,6 +232,33 @@ promptexpand(char *s, int ns, char *rs, char *Rs, unsigned int *txtchangep)
return new_vars.buf;
}
+/* Parse the argument for %F and %K */
+static int
+parsecolorchar(int arg, int is_fg)
+{
+ if (bv->fm[1] == '{') {
+ char *ep;
+ bv->fm += 2; /* skip over F{ */
+ if ((ep = strchr(bv->fm, '}'))) {
+ char oc = *ep, *col, *coll;
+ *ep = '\0';
+ /* expand the contents of the argument so you can use
+ * %v for example */
+ coll = col = promptexpand(bv->fm, 0, NULL, NULL, NULL);
+ *ep = oc;
+ arg = match_colour((const char **)&coll, is_fg, 0);
+ free(col);
+ bv->fm = ep;
+ } else {
+ arg = match_colour((const char **)&bv->fm, is_fg, 0);
+ if (*bv->fm != '}')
+ bv->fm--;
+ }
+ } else
+ arg = match_colour(NULL, 1, arg);
+ return arg;
+}
+
/* Perform %- and !-expansion as required on a section of the prompt. The *
* section is ended by an instance of endchar. If doprint is 0, the valid *
* % sequences are merely skipped over, and nothing is stored. */
@@ -494,13 +521,7 @@ putpromptchar(int doprint, int endchar, unsigned int *txtchangep)
tsetcap(TCUNDERLINEEND, TSC_PROMPT|TSC_DIRTY);
break;
case 'F':
- if (bv->fm[1] == '{') {
- bv->fm += 2;
- arg = match_colour((const char **)&bv->fm, 1, 0);
- if (*bv->fm != '}')
- bv->fm--;
- } else
- arg = match_colour(NULL, 1, arg);
+ arg = parsecolorchar(arg, 1);
if (arg >= 0 && !(arg & TXTNOFGCOLOUR)) {
txtchangeset(txtchangep, arg & TXT_ATTR_FG_ON_MASK,
TXTNOFGCOLOUR);
@@ -515,13 +536,7 @@ putpromptchar(int doprint, int endchar, unsigned int *txtchangep)
set_colour_attribute(TXTNOFGCOLOUR, COL_SEQ_FG, TSC_PROMPT);
break;
case 'K':
- if (bv->fm[1] == '{') {
- bv->fm += 2;
- arg = match_colour((const char **)&bv->fm, 0, 0);
- if (*bv->fm != '}')
- bv->fm--;
- } else
- arg = match_colour(NULL, 0, arg);
+ arg = parsecolorchar(arg, 0);
if (arg >= 0 && !(arg & TXTNOBGCOLOUR)) {
txtchangeset(txtchangep, arg & TXT_ATTR_BG_ON_MASK,
TXTNOBGCOLOUR);
--
1.7.10.GIT
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2012-05-31 20:27 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-05-03 19:00 PATCH (RFC): Parse argument to %F and %K as prompt sequences Mikael Magnusson
2012-05-31 19:56 ` PATCH: " Mikael Magnusson
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).