mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-05-22 00:11:30 +02:00
52499: support highlight groups
These are defined in a .zle.hlgroups associative array and referenced using %H in prompt strings or hl= in zle_highlight/region_highlight.
This commit is contained in:
parent
8e622c25b2
commit
3c5dacd503
2 changed files with 52 additions and 2 deletions
|
@ -1,5 +1,9 @@
|
|||
2024-01-28 Oliver Kiddle <opk@zsh.org>
|
||||
|
||||
* 52499: Src/prompt.c: support highlight groups defined in a
|
||||
.zle.hlgroups associative array and referenced using %H in
|
||||
prompt strings or hl= in zle_highlight/region_highlight
|
||||
|
||||
* unposted: Src/Modules/zutil.c: remove unused variable to silence
|
||||
compiler warning
|
||||
|
||||
|
|
50
Src/prompt.c
50
Src/prompt.c
|
@ -241,6 +241,39 @@ promptexpand(char *s, int ns, char *rs, char *Rs)
|
|||
return new_vars.buf;
|
||||
}
|
||||
|
||||
/* Parse the argument for %H */
|
||||
static char *
|
||||
parsehighlight(char *arg, char endchar, zattr *atr)
|
||||
{
|
||||
static int entered = 0;
|
||||
char *var = ".zle.hlgroups";
|
||||
struct value vbuf;
|
||||
Value v;
|
||||
char *ep, *attrs;
|
||||
if ((ep = strchr(arg, endchar)))
|
||||
*ep = '\0';
|
||||
if (!entered && (v = getvalue(&vbuf, &var, 0)) &&
|
||||
PM_TYPE(v->pm->node.flags) == PM_HASHED)
|
||||
{
|
||||
Param node;
|
||||
HashTable ht = v->pm->gsu.h->getfn(v->pm);
|
||||
if ((node = (Param) ht->getnode(ht, arg))) {
|
||||
attrs = node->gsu.s->getfn(node);
|
||||
entered = 1;
|
||||
if (match_highlight(attrs, atr) == attrs)
|
||||
*atr = TXT_ERROR;
|
||||
} else
|
||||
*atr = TXT_ERROR;
|
||||
} else
|
||||
*atr = TXT_ERROR;
|
||||
if (ep)
|
||||
*ep = endchar;
|
||||
else
|
||||
ep = strchr(arg, '\0') - 1;
|
||||
entered = 0;
|
||||
return ep;
|
||||
}
|
||||
|
||||
/* Parse the argument for %F and %K */
|
||||
static zattr
|
||||
parsecolorchar(zattr arg, int is_fg)
|
||||
|
@ -571,6 +604,13 @@ putpromptchar(int doprint, int endchar)
|
|||
tunsetattrs(TXTBGCOLOUR);
|
||||
applytextattributes(TSC_PROMPT);
|
||||
break;
|
||||
case 'H':
|
||||
bv->fm = parsehighlight(bv->fm + 2, '}', &atr);
|
||||
if (atr != TXT_ERROR) {
|
||||
treplaceattrs(atr);
|
||||
applytextattributes(TSC_PROMPT);
|
||||
}
|
||||
break;
|
||||
case '[':
|
||||
if (idigit(*++bv->fm))
|
||||
arg = zstrtol(bv->fm, &bv->fm, 10);
|
||||
|
@ -1856,11 +1896,17 @@ match_highlight(const char *teststr, zattr *on_var)
|
|||
*on_var = 0;
|
||||
while (found && *teststr) {
|
||||
const struct highlight *hl;
|
||||
zattr atr = 0;
|
||||
|
||||
found = 0;
|
||||
if (strpfx("fg=", teststr) || strpfx("bg=", teststr)) {
|
||||
if (strpfx("hl=", teststr)) {
|
||||
teststr += 3;
|
||||
teststr = parsehighlight((char *)teststr, ',', &atr);
|
||||
if (atr != TXT_ERROR)
|
||||
*on_var = atr;
|
||||
found = 1;
|
||||
} else if (strpfx("fg=", teststr) || strpfx("bg=", teststr)) {
|
||||
int is_fg = (teststr[0] == 'f');
|
||||
zattr atr;
|
||||
|
||||
teststr += 3;
|
||||
atr = match_colour(&teststr, is_fg, 0);
|
||||
|
|
Loading…
Reference in a new issue