mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-06-10 18:58:03 +02:00
52646: extend support for highlight groups to completion explanation strings and WATCHFMT
This commit is contained in:
parent
36a2d5cfa4
commit
05c7b21e2b
8 changed files with 50 additions and 17 deletions
|
@ -1,5 +1,10 @@
|
||||||
2024-03-05 Oliver Kiddle <opk@zsh.org>
|
2024-03-05 Oliver Kiddle <opk@zsh.org>
|
||||||
|
|
||||||
|
* 52646: Completion/Zsh/Type/_ps1234, Doc/Zsh/compsys.yo,
|
||||||
|
Doc/Zsh/compwid.yo, Src/Modules/watch.c, Src/Zle/complist.c,
|
||||||
|
Src/Zle/zle_tricky.c, Src/prompt.c: extend support for highlight
|
||||||
|
groups to completion explanation strings and WATCHFMT
|
||||||
|
|
||||||
* 52641: midchildan: Doc/Zsh/contrib.yo, Functions/Zle/incarg,
|
* 52641: midchildan: Doc/Zsh/contrib.yo, Functions/Zle/incarg,
|
||||||
Test/X05zleincarg.ztst: add a backward variant and make it repeatable
|
Test/X05zleincarg.ztst: add a backward variant and make it repeatable
|
||||||
|
|
||||||
|
@ -31,8 +36,6 @@
|
||||||
|
|
||||||
* 52623: Src/signames2.awk: add some Solaris signal descriptions
|
* 52623: Src/signames2.awk: add some Solaris signal descriptions
|
||||||
|
|
||||||
2024-02-28 Oliver Kiddle <opk@zsh.org>
|
|
||||||
|
|
||||||
* 52594: Completion/Zsh/Command/_kill, Doc/Zsh/builtins.yo,
|
* 52594: Completion/Zsh/Command/_kill, Doc/Zsh/builtins.yo,
|
||||||
Doc/Zsh/params.yo, Src/Modules/parameter.c, Src/builtin.c,
|
Doc/Zsh/params.yo, Src/Modules/parameter.c, Src/builtin.c,
|
||||||
Src/exec.c, Src/hashtable.c, Src/init.c, Src/jobs.c, Src/params.c,
|
Src/exec.c, Src/hashtable.c, Src/init.c, Src/jobs.c, Src/params.c,
|
||||||
|
|
|
@ -1,17 +1,18 @@
|
||||||
#compdef -value-,PROMPT,-default- -value-,PROMPT2,-default- -value-,PROMPT3,-default- -value-,PROMPT4,-default- -value-,RPROMPT,-default- -value-,RPROMPT2,-default- -value-,PS1,-default- -value-,PS2,-default- -value-,PS3,-default- -value-,PS4,-default- -value-,RPS1,-default- -value-,RPS2,-default- -value-,SPROMPT,-default- -value-,PROMPT_EOL_MARK,-default-
|
#compdef -value-,PROMPT,-default- -value-,PROMPT2,-default- -value-,PROMPT3,-default- -value-,PROMPT4,-default- -value-,RPROMPT,-default- -value-,RPROMPT2,-default- -value-,PS1,-default- -value-,PS2,-default- -value-,PS3,-default- -value-,PS4,-default- -value-,RPS1,-default- -value-,RPS2,-default- -value-,SPROMPT,-default- -value-,PROMPT_EOL_MARK,-default-
|
||||||
|
|
||||||
local -a specs ccol
|
local -a specs ccol suf
|
||||||
local expl grp cols bs suf pre changed=1 ret=1
|
local expl grp cols bs pre changed=1 ret=1
|
||||||
local -A ansi
|
local -A ansi
|
||||||
|
|
||||||
[[ -z $compstate[quote] ]] && bs='\'
|
[[ -z $compstate[quote] ]] && bs='\'
|
||||||
|
suf=( -S '' )
|
||||||
|
|
||||||
# first strip off any complete prompt specifications leaving only the
|
# first strip off any complete prompt specifications leaving only the
|
||||||
# current, incomplete, one
|
# current, incomplete, one
|
||||||
while (( changed )); do
|
while (( changed )); do
|
||||||
changed=0
|
changed=0
|
||||||
compset -P '%[DFK](\\|){[^}]#}' && changed=1 # formats with arg: %x{...}
|
compset -P '%[DFHK](\\|){[^}]#}' && changed=1 # formats with arg: %x{...}
|
||||||
compset -P '%[0-9-\\]#[^DFK(0-9-<>\\\[]' && changed=1 # normal formats
|
compset -P '%[0-9-\\]#[^DFHK(0-9-<>\\\[]' && changed=1 # normal formats
|
||||||
compset -P '%[0-9-\\]#(<[^<]#<|>[^>]#>|\[[^\]]#\])' && changed=1 # truncations
|
compset -P '%[0-9-\\]#(<[^<]#<|>[^>]#>|\[[^\]]#\])' && changed=1 # truncations
|
||||||
compset -P '%[0-9-\\]#(\\|)\([0-9-]#[^0-9]?|[^%]' && changed=1 # start of ternary
|
compset -P '%[0-9-\\]#(\\|)\([0-9-]#[^0-9]?|[^%]' && changed=1 # start of ternary
|
||||||
compset -P '[^%]##' && changed=1 # sundry other characters
|
compset -P '[^%]##' && changed=1 # sundry other characters
|
||||||
|
@ -41,15 +42,15 @@ if compset -P '%[FK]'; then
|
||||||
grp="$expl[expl[(i)-J]+1]"
|
grp="$expl[expl[(i)-J]+1]"
|
||||||
print -v ccol -f "($grp)=%s=%s" ${(kv)ansi}
|
print -v ccol -f "($grp)=%s=%s" ${(kv)ansi}
|
||||||
_comp_colors+=( $ccol )
|
_comp_colors+=( $ccol )
|
||||||
compadd "$expl[@]" $suf $pre -k ansi && ret=0
|
compadd "$expl[@]" "$suf[@]" $pre -k ansi && ret=0
|
||||||
if (( $#suf )) && compset -P "(<->|%v)"; then
|
if [[ $ISUFFIX != (\\|)}* ]] && compset -P "(<->|%v)"; then
|
||||||
_wanted ansi-colors expl 'closing brace' compadd -S '' \} && ret=0
|
_wanted ansi-colors expl 'closing brace' compadd -S '' \} && ret=0
|
||||||
elif (( $+terminfo[colors] )); then
|
elif (( $+terminfo[colors] )); then
|
||||||
(( cols = $terminfo[colors] - 1 ))
|
(( cols = $terminfo[colors] - 1 ))
|
||||||
(( cols = cols > 255 ? 255 : cols ))
|
(( cols = cols > 255 ? 255 : cols ))
|
||||||
_description -V terminal-colors expl 'terminal color'
|
_description -V terminal-colors expl 'terminal color'
|
||||||
grp="$expl[expl[(i)-J]+1]"
|
grp="$expl[expl[(i)-J]+1]"
|
||||||
compadd "$expl[@]" $suf $pre {0..$cols}
|
compadd "$expl[@]" "$suf[@]" $pre {0..$cols}
|
||||||
for c in {0..$cols}; do
|
for c in {0..$cols}; do
|
||||||
_comp_colors+=( "($grp)=${c}=${${${(%):-%F{$c\}}#?\[}%m}" )
|
_comp_colors+=( "($grp)=${c}=${${${(%):-%F{$c\}}#?\[}%m}" )
|
||||||
done
|
done
|
||||||
|
@ -93,11 +94,14 @@ elif compset -P '%[0-9-\\]#(\\|)\([0-9-]#'; then
|
||||||
'w:day of week (Sunday = 0)'
|
'w:day of week (Sunday = 0)'
|
||||||
)
|
)
|
||||||
[[ $IPREFIX != *- ]] && _describe -t ternary-prompt-expressions \
|
[[ $IPREFIX != *- ]] && _describe -t ternary-prompt-expressions \
|
||||||
'ternary prompt format test character' specs $suf && ret=0
|
'ternary prompt format test character' specs "$suf[@]" && ret=0
|
||||||
_message -e numbers number
|
_message -e numbers number
|
||||||
elif compset -P '%D(\\|){'; then
|
elif compset -P '%D(\\|){'; then
|
||||||
compset -S '(\\|)}*'
|
compset -S '(\\|)}*'
|
||||||
_date_formats zsh && ret=0
|
_date_formats zsh && ret=0
|
||||||
|
elif compset -P '%H(\\|){'; then
|
||||||
|
compset -S '(\\|)}*' || suf=( -S "$bs}" )
|
||||||
|
_wanted highlight-groups expl 'highlight group' compadd "$suf[@]" -k .zle.hlgroups && ret=0
|
||||||
elif [[ -prefix '%' ]] ||
|
elif [[ -prefix '%' ]] ||
|
||||||
! zstyle -t ":completion:${curcontext}:prompt-format-specifiers" prefix-needed
|
! zstyle -t ":completion:${curcontext}:prompt-format-specifiers" prefix-needed
|
||||||
then
|
then
|
||||||
|
@ -152,6 +156,7 @@ then
|
||||||
'B:start bold'
|
'B:start bold'
|
||||||
'b:stop bold'
|
'b:stop bold'
|
||||||
'E:clear to end of line'
|
'E:clear to end of line'
|
||||||
|
'H{:use highlight group'
|
||||||
'U:start underline'
|
'U:start underline'
|
||||||
'u:stop underline'
|
'u:stop underline'
|
||||||
'S:start standout'
|
'S:start standout'
|
||||||
|
|
|
@ -2023,8 +2023,8 @@ position shown as a percentage of the total length otherwise. In each
|
||||||
case the form with the uppercase letter will be replaced by a string of fixed
|
case the form with the uppercase letter will be replaced by a string of fixed
|
||||||
width, padded to the right with spaces, while the lowercase form will
|
width, padded to the right with spaces, while the lowercase form will
|
||||||
be replaced by a variable width string. As in other prompt strings, the
|
be replaced by a variable width string. As in other prompt strings, the
|
||||||
escape sequences `tt(%S)', `tt(%s)', `tt(%B)', `tt(%b)', `tt(%U)',
|
escape sequence `tt(%H)` along with `tt(%S)', `tt(%s)', `tt(%B)', `tt(%b)',
|
||||||
`tt(%u)' for entering and leaving the display modes
|
`tt(%U)', `tt(%u)' for entering and leaving the display modes
|
||||||
standout, bold and underline, and `tt(%F)', `tt(%f)', `tt(%K)', `tt(%k)' for
|
standout, bold and underline, and `tt(%F)', `tt(%f)', `tt(%K)', `tt(%k)' for
|
||||||
changing the foreground background colour, are also available, as is the form
|
changing the foreground background colour, are also available, as is the form
|
||||||
`tt(%{)...tt(%})' for enclosing escape sequences which display with zero
|
`tt(%{)...tt(%})' for enclosing escape sequences which display with zero
|
||||||
|
|
|
@ -597,7 +597,8 @@ ifnzman((see noderef(Prompt Expansion)))\
|
||||||
ifzman(as described in the section EXPANSION OF PROMPT SEQUENCES in
|
ifzman(as described in the section EXPANSION OF PROMPT SEQUENCES in
|
||||||
zmanref(zshmisc)):
|
zmanref(zshmisc)):
|
||||||
`tt(%B)', `tt(%S)', `tt(%U)', `tt(%F)', `tt(%K)' and their lower case
|
`tt(%B)', `tt(%S)', `tt(%U)', `tt(%F)', `tt(%K)' and their lower case
|
||||||
counterparts, as well as `tt(%{)...tt(%})'. `tt(%F)', `tt(%K)' and
|
counterparts, as well as `tt(%H)' and `tt(%{)...tt(%})'. `tt(%F)',
|
||||||
|
`tt(%K)', `tt(%H)' and
|
||||||
`tt(%{)...tt(%})' take arguments in the same form as prompt
|
`tt(%{)...tt(%})' take arguments in the same form as prompt
|
||||||
expansion. (Note that the sequence `tt(%G)' is not available; an
|
expansion. (Note that the sequence `tt(%G)' is not available; an
|
||||||
argument to `tt(%{)' should be used instead.) The sequence `tt(%%)'
|
argument to `tt(%{)' should be used instead.) The sequence `tt(%%)'
|
||||||
|
|
|
@ -373,6 +373,13 @@ watchlog2(int inout, WATCH_STRUCT_UTMP *u, char *fmt, int prnt, int fini)
|
||||||
case 'f':
|
case 'f':
|
||||||
tunsetattrs(TXTFGCOLOUR);
|
tunsetattrs(TXTFGCOLOUR);
|
||||||
break;
|
break;
|
||||||
|
case 'H':
|
||||||
|
if (*fmt == '{') {
|
||||||
|
fmt = parsehighlight(fmt + 1, '}', &atr);
|
||||||
|
if (atr && atr != TXT_ERROR)
|
||||||
|
treplaceattrs(atr);
|
||||||
|
}
|
||||||
|
break;
|
||||||
case 'K':
|
case 'K':
|
||||||
if (*fmt == '{') {
|
if (*fmt == '{') {
|
||||||
fmt++;
|
fmt++;
|
||||||
|
@ -428,7 +435,7 @@ watchlog_match(char *teststr, char *actual, size_t buflen)
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
Patprog pprog;
|
Patprog pprog;
|
||||||
char *str = dupstring(teststr);
|
char *str = dupstring(teststr);
|
||||||
int len = strnlen(actual, buflen);
|
size_t len = strnlen(actual, buflen);
|
||||||
char *user = metafy(actual, len,
|
char *user = metafy(actual, len,
|
||||||
len == buflen ? META_HEAPDUP : META_USEHEAP);
|
len == buflen ? META_HEAPDUP : META_USEHEAP);
|
||||||
|
|
||||||
|
|
|
@ -1181,6 +1181,13 @@ compprintfmt(char *fmt, int n, int dopr, int doesc, int ml, int *stop)
|
||||||
if (dopr)
|
if (dopr)
|
||||||
tunsetattrs(TXTBGCOLOUR);
|
tunsetattrs(TXTBGCOLOUR);
|
||||||
break;
|
break;
|
||||||
|
case ZWC('H'):
|
||||||
|
if (*p == '{') {
|
||||||
|
p = parsehighlight(p + 1, '}', &atr);
|
||||||
|
if (atr != TXT_ERROR && dopr)
|
||||||
|
treplaceattrs(atr);
|
||||||
|
}
|
||||||
|
break;
|
||||||
case ZWC('{'):
|
case ZWC('{'):
|
||||||
if (arg)
|
if (arg)
|
||||||
cc += arg;
|
cc += arg;
|
||||||
|
|
|
@ -2501,6 +2501,14 @@ printfmt(char *fmt, int n, int dopr, int doesc)
|
||||||
case 'k':
|
case 'k':
|
||||||
tunsetattrs(TXTBGCOLOUR);
|
tunsetattrs(TXTBGCOLOUR);
|
||||||
break;
|
break;
|
||||||
|
case 'H':
|
||||||
|
if (p[1] == '{') {
|
||||||
|
p = parsehighlight(p + 2, '}', &atr);
|
||||||
|
--p;
|
||||||
|
if (atr != TXT_ERROR)
|
||||||
|
treplaceattrs(atr);
|
||||||
|
}
|
||||||
|
break;
|
||||||
case '{':
|
case '{':
|
||||||
if (arg)
|
if (arg)
|
||||||
cc += arg;
|
cc += arg;
|
||||||
|
|
|
@ -270,7 +270,8 @@ zattrescape(zattr atr, int *len)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Parse the argument for %H */
|
/* Parse the argument for %H */
|
||||||
static char *
|
/**/
|
||||||
|
mod_export char *
|
||||||
parsehighlight(char *arg, char endchar, zattr *atr)
|
parsehighlight(char *arg, char endchar, zattr *atr)
|
||||||
{
|
{
|
||||||
static int entered = 0;
|
static int entered = 0;
|
||||||
|
@ -295,9 +296,9 @@ parsehighlight(char *arg, char endchar, zattr *atr)
|
||||||
} else
|
} else
|
||||||
*atr = TXT_ERROR;
|
*atr = TXT_ERROR;
|
||||||
if (ep)
|
if (ep)
|
||||||
*ep = endchar;
|
*ep++ = endchar;
|
||||||
else
|
else
|
||||||
ep = strchr(arg, '\0') - 1;
|
ep = strchr(arg, '\0');
|
||||||
entered = 0;
|
entered = 0;
|
||||||
return ep;
|
return ep;
|
||||||
}
|
}
|
||||||
|
@ -635,6 +636,7 @@ putpromptchar(int doprint, int endchar)
|
||||||
case 'H':
|
case 'H':
|
||||||
if (bv->fm[1] == '{') {
|
if (bv->fm[1] == '{') {
|
||||||
bv->fm = parsehighlight(bv->fm + 2, '}', &atr);
|
bv->fm = parsehighlight(bv->fm + 2, '}', &atr);
|
||||||
|
--bv->fm;
|
||||||
if (atr != TXT_ERROR) {
|
if (atr != TXT_ERROR) {
|
||||||
treplaceattrs(atr);
|
treplaceattrs(atr);
|
||||||
applytextattributes(TSC_PROMPT);
|
applytextattributes(TSC_PROMPT);
|
||||||
|
|
Loading…
Reference in a new issue