mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-09-26 18:01:03 +02:00
30496: Parse argument to %F and %K as prompt sequences
This commit is contained in:
parent
26694406f2
commit
8a9b141652
2 changed files with 36 additions and 15 deletions
|
@ -1,3 +1,9 @@
|
||||||
|
2013-03-10 Mikael Magnusson <mikachu@gmail.com>
|
||||||
|
|
||||||
|
* 30496: Src/prompt.c: Parse argument to %F and %K as prompt
|
||||||
|
sequences. This allows constructs like %F{%3v} to use $psvar[3]
|
||||||
|
for the color.
|
||||||
|
|
||||||
2013-03-05 Peter Stephenson <p.w.stephenson@ntlworld.com>
|
2013-03-05 Peter Stephenson <p.w.stephenson@ntlworld.com>
|
||||||
|
|
||||||
* users/17666: Doc/Zsh/contrib.yo, Functions/Misc/zcalc: -f
|
* users/17666: Doc/Zsh/contrib.yo, Functions/Misc/zcalc: -f
|
||||||
|
@ -561,5 +567,5 @@
|
||||||
|
|
||||||
*****************************************************
|
*****************************************************
|
||||||
* This is used by the shell to define $ZSH_PATCHLEVEL
|
* This is used by the shell to define $ZSH_PATCHLEVEL
|
||||||
* $Revision: 1.5812 $
|
* $Revision: 1.5813 $
|
||||||
*****************************************************
|
*****************************************************
|
||||||
|
|
43
Src/prompt.c
43
Src/prompt.c
|
@ -232,6 +232,33 @@ promptexpand(char *s, int ns, char *rs, char *Rs, unsigned int *txtchangep)
|
||||||
return new_vars.buf;
|
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 *
|
/* 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 *
|
* section is ended by an instance of endchar. If doprint is 0, the valid *
|
||||||
* % sequences are merely skipped over, and nothing is stored. */
|
* % 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);
|
tsetcap(TCUNDERLINEEND, TSC_PROMPT|TSC_DIRTY);
|
||||||
break;
|
break;
|
||||||
case 'F':
|
case 'F':
|
||||||
if (bv->fm[1] == '{') {
|
arg = parsecolorchar(arg, 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);
|
|
||||||
if (arg >= 0 && !(arg & TXTNOFGCOLOUR)) {
|
if (arg >= 0 && !(arg & TXTNOFGCOLOUR)) {
|
||||||
txtchangeset(txtchangep, arg & TXT_ATTR_FG_ON_MASK,
|
txtchangeset(txtchangep, arg & TXT_ATTR_FG_ON_MASK,
|
||||||
TXTNOFGCOLOUR);
|
TXTNOFGCOLOUR);
|
||||||
|
@ -515,13 +536,7 @@ putpromptchar(int doprint, int endchar, unsigned int *txtchangep)
|
||||||
set_colour_attribute(TXTNOFGCOLOUR, COL_SEQ_FG, TSC_PROMPT);
|
set_colour_attribute(TXTNOFGCOLOUR, COL_SEQ_FG, TSC_PROMPT);
|
||||||
break;
|
break;
|
||||||
case 'K':
|
case 'K':
|
||||||
if (bv->fm[1] == '{') {
|
arg = parsecolorchar(arg, 0);
|
||||||
bv->fm += 2;
|
|
||||||
arg = match_colour((const char **)&bv->fm, 0, 0);
|
|
||||||
if (*bv->fm != '}')
|
|
||||||
bv->fm--;
|
|
||||||
} else
|
|
||||||
arg = match_colour(NULL, 0, arg);
|
|
||||||
if (arg >= 0 && !(arg & TXTNOBGCOLOUR)) {
|
if (arg >= 0 && !(arg & TXTNOBGCOLOUR)) {
|
||||||
txtchangeset(txtchangep, arg & TXT_ATTR_BG_ON_MASK,
|
txtchangeset(txtchangep, arg & TXT_ATTR_BG_ON_MASK,
|
||||||
TXTNOBGCOLOUR);
|
TXTNOBGCOLOUR);
|
||||||
|
|
Loading…
Reference in a new issue