From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.5 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 Received: from zero.zsh.org (zero.zsh.org [IPv6:2a02:898:31:0:48:4558:7a:7368]) by inbox.vuxu.org (Postfix) with ESMTP id 37482280BD for ; Sat, 2 Mar 2024 02:21:50 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Message-ID:Date: Content-Transfer-Encoding:Content-ID:Content-Type:MIME-Version:Subject:To: From:Reply-To:Cc:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References; bh=idhfwouPAYIx6+vTQ4XBWvaXzoi4O8Yx0kZMRoP57Z4=; b=gBaTwaSKVHwokkUBJ/3kPEPETi J995BI9T9C7r/yP6tGY+HCbo1aE93WjXr+ur+f5FOKZ8wU6BYJYyRyoC+EwSDbi3MjcKq5C87Ytsz hQk2HE8b/daDoQWQsDPSzhiDh69CsDS0Qi56HvRGmepv0QtU6ZaebRp7L97qCfYFJUe1xSiHTw+N3 yQRkx5TRXkwtk/zjqmz3fDWzfuFHjFL27rF4OD5cJmSjKZP4StUEGAYr7PH+x0hIhmL/Xl4L1VXqp FQhasp3Gisk2cit/8YVmp7HRLjAa+9aTSddGULnWHy4WiI8Vg1O4SlpVToRkmP5H/uMnn41DsLvqB 5hj84BjA==; Received: by zero.zsh.org with local id 1rgE4U-0008G0-8o; Sat, 02 Mar 2024 01:21:50 +0000 Received: by zero.zsh.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256) id 1rgE4E-0007vl-Ql; Sat, 02 Mar 2024 01:21:35 +0000 Received: from [192.168.178.21] (helo=hydra) by mail.kiddle.eu with esmtp(Exim 4.97.1) (envelope-from ) id 1rgE4D-00000000New-0eSZ for zsh-workers@zsh.org; Sat, 02 Mar 2024 02:21:33 +0100 From: Oliver Kiddle To: Zsh workers Subject: PATCH: broader support for highlight groups MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <90948.1709342493.1@hydra> Content-Transfer-Encoding: quoted-printable Date: Sat, 02 Mar 2024 02:21:33 +0100 Message-ID: <90949-1709342493.093890@W3fn.AXo8.ESGa> X-Seq: 52646 Archived-At: X-Loop: zsh-workers@zsh.org Errors-To: zsh-workers-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-workers-request@zsh.org X-no-archive: yes List-Id: List-Help: , List-Subscribe: , List-Unsubscribe: , List-Post: List-Owner: List-Archive: This broadens the support for %H to completion explanation strings (with and without complist) and WATCHFMT, both of which already support %B/%S/%U/%F/%K. This also affects the list-prompt style as a side-effect. Completion for prompt strings also gains support for %H. The return value from parsehighlight() has been changed to go one past the end character because that's now convenient for more of the callers than leaving it on the end character. The one change of int to size_t in watch.c is to silence a (-Wextra) compiler warning. We still lack a way to reset attributes. Rather than %r, which does have tenuous conflicts with completion explanations and some obscure uses of zformat, I'm tending towards special-casing %H{reset} and/or %H{none}. And perhaps disabling the feature of allowing left-over attributes in the prompt to bleed over into the user's input where those attributes came from a highlight group. That feature only exists for backward-compatibility and anyone using a new feature like highlight groups can also set the default key in zle_highlight. Any opinions? Oliver diff --git a/Completion/Zsh/Type/_ps1234 b/Completion/Zsh/Type/_ps1234 index 07dea5905..e4391dc00 100644 --- a/Completion/Zsh/Type/_ps1234 +++ b/Completion/Zsh/Type/_ps1234 @@ -1,17 +1,18 @@ #compdef -value-,PROMPT,-default- -value-,PROMPT2,-default- -value-,PROMP= T3,-default- -value-,PROMPT4,-default- -value-,RPROMPT,-default- -value-,R= PROMPT2,-default- -value-,PS1,-default- -value-,PS2,-default- -value-,PS3,= -default- -value-,PS4,-default- -value-,RPS1,-default- -value-,RPS2,-defau= lt- -value-,SPROMPT,-default- -value-,PROMPT_EOL_MARK,-default- = -local -a specs ccol -local expl grp cols bs suf pre changed=3D1 ret=3D1 +local -a specs ccol suf +local expl grp cols bs pre changed=3D1 ret=3D1 local -A ansi = [[ -z $compstate[quote] ]] && bs=3D'\' +suf=3D( -S '' ) = # first strip off any complete prompt specifications leaving only the # current, incomplete, one while (( changed )); do changed=3D0 - compset -P '%[DFK](\\|){[^}]#}' && changed=3D1 # formats with arg: %x{.= ..} - compset -P '%[0-9-\\]#[^DFK(0-9-<>\\\[]' && changed=3D1 # normal format= s + compset -P '%[DFHK](\\|){[^}]#}' && changed=3D1 # formats with arg: %x{= ...} + compset -P '%[0-9-\\]#[^DFHK(0-9-<>\\\[]' && changed=3D1 # normal forma= ts compset -P '%[0-9-\\]#(<[^<]#<|>[^>]#>|\[[^\]]#\])' && changed=3D1 # tr= uncations compset -P '%[0-9-\\]#(\\|)\([0-9-]#[^0-9]?|[^%]' && changed=3D1 # star= t of ternary compset -P '[^%]##' && changed=3D1 # sundry other characters @@ -41,15 +42,15 @@ if compset -P '%[FK]'; then grp=3D"$expl[expl[(i)-J]+1]" print -v ccol -f "($grp)=3D%s=3D%s" ${(kv)ansi} _comp_colors+=3D( $ccol ) - compadd "$expl[@]" $suf $pre -k ansi && ret=3D0 - if (( $#suf )) && compset -P "(<->|%v)"; then + compadd "$expl[@]" "$suf[@]" $pre -k ansi && ret=3D0 + if [[ $ISUFFIX !=3D (\\|)}* ]] && compset -P "(<->|%v)"; then _wanted ansi-colors expl 'closing brace' compadd -S '' \} && ret=3D0 elif (( $+terminfo[colors] )); then (( cols =3D $terminfo[colors] - 1 )) (( cols =3D cols > 255 ? 255 : cols )) _description -V terminal-colors expl 'terminal color' grp=3D"$expl[expl[(i)-J]+1]" - compadd "$expl[@]" $suf $pre {0..$cols} + compadd "$expl[@]" "$suf[@]" $pre {0..$cols} for c in {0..$cols}; do _comp_colors+=3D( "($grp)=3D${c}=3D${${${(%):-%F{$c\}}#?\[}%m}" ) done @@ -93,11 +94,14 @@ elif compset -P '%[0-9-\\]#(\\|)\([0-9-]#'; then 'w:day of week (Sunday =3D 0)' ) [[ $IPREFIX !=3D *- ]] && _describe -t ternary-prompt-expressions \ - 'ternary prompt format test character' specs $suf && ret=3D0 + 'ternary prompt format test character' specs "$suf[@]" && ret=3D0 _message -e numbers number elif compset -P '%D(\\|){'; then compset -S '(\\|)}*' _date_formats zsh && ret=3D0 +elif compset -P '%H(\\|){'; then + compset -S '(\\|)}*' || suf=3D( -S "$bs}" ) + _wanted highlight-groups expl 'highlight group' compadd "$suf[@]" -k .z= le.hlgroups && ret=3D0 elif [[ -prefix '%' ]] || ! zstyle -t ":completion:${curcontext}:prompt-format-specifiers" pr= efix-needed then @@ -152,6 +156,7 @@ then 'B:start bold' 'b:stop bold' 'E:clear to end of line' + 'H{:use highlight group' 'U:start underline' 'u:stop underline' 'S:start standout' diff --git a/Doc/Zsh/compsys.yo b/Doc/Zsh/compsys.yo index 3f708eb5a..f75298a1b 100644 --- a/Doc/Zsh/compsys.yo +++ b/Doc/Zsh/compsys.yo @@ -2023,8 +2023,8 @@ position shown as a percentage of the total length o= therwise. In each case the form with the uppercase letter will be replaced by a string of f= ixed 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 -escape sequences `tt(%S)', `tt(%s)', `tt(%B)', `tt(%b)', `tt(%U)', -`tt(%u)' for entering and leaving the display modes +escape sequence `tt(%H)` along with `tt(%S)', `tt(%s)', `tt(%B)', `tt(%b)= ', +`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 changing the foreground background colour, are also available, as is the = form `tt(%{)...tt(%})' for enclosing escape sequences which display with zero diff --git a/Doc/Zsh/compwid.yo b/Doc/Zsh/compwid.yo index 9461ace17..b0c9b0a5f 100644 --- a/Doc/Zsh/compwid.yo +++ b/Doc/Zsh/compwid.yo @@ -597,7 +597,8 @@ ifnzman((see noderef(Prompt Expansion)))\ ifzman(as described in the section EXPANSION OF PROMPT SEQUENCES in zmanref(zshmisc)): `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 expansion. (Note that the sequence `tt(%G)' is not available; an argument to `tt(%{)' should be used instead.) The sequence `tt(%%)' diff --git a/Src/Modules/watch.c b/Src/Modules/watch.c index 97d4fa608..ba17cf940 100644 --- a/Src/Modules/watch.c +++ b/Src/Modules/watch.c @@ -373,6 +373,13 @@ watchlog2(int inout, WATCH_STRUCT_UTMP *u, char *fmt,= int prnt, int fini) case 'f': tunsetattrs(TXTFGCOLOUR); break; + case 'H': + if (*fmt =3D=3D '{') { + fmt =3D parsehighlight(fmt + 1, '}', &atr); + if (atr && atr !=3D TXT_ERROR) + treplaceattrs(atr); + } + break; case 'K': if (*fmt =3D=3D '{') { fmt++; @@ -428,7 +435,7 @@ watchlog_match(char *teststr, char *actual, size_t buf= len) int ret =3D 0; Patprog pprog; char *str =3D dupstring(teststr); - int len =3D strnlen(actual, buflen); + size_t len =3D strnlen(actual, buflen); char *user =3D metafy(actual, len, len =3D=3D buflen ? META_HEAPDUP : META_USEHEAP); = diff --git a/Src/Zle/complist.c b/Src/Zle/complist.c index 9cb89a60d..5619160a9 100644 --- a/Src/Zle/complist.c +++ b/Src/Zle/complist.c @@ -1181,6 +1181,13 @@ compprintfmt(char *fmt, int n, int dopr, int doesc,= int ml, int *stop) if (dopr) tunsetattrs(TXTBGCOLOUR); break; + case ZWC('H'): + if (*p =3D=3D '{') { + p =3D parsehighlight(p + 1, '}', &atr); + if (atr !=3D TXT_ERROR && dopr) + treplaceattrs(atr); + } + break; case ZWC('{'): if (arg) cc +=3D arg; diff --git a/Src/Zle/zle_tricky.c b/Src/Zle/zle_tricky.c index 225ce8c74..aa3c71bc2 100644 --- a/Src/Zle/zle_tricky.c +++ b/Src/Zle/zle_tricky.c @@ -2501,6 +2501,14 @@ printfmt(char *fmt, int n, int dopr, int doesc) case 'k': tunsetattrs(TXTBGCOLOUR); break; + case 'H': + if (p[1] =3D=3D '{') { + p =3D parsehighlight(p + 2, '}', &atr); + --p; + if (atr !=3D TXT_ERROR) + treplaceattrs(atr); + } + break; case '{': if (arg) cc +=3D arg; diff --git a/Src/prompt.c b/Src/prompt.c index 7acbe0e47..e10b05215 100644 --- a/Src/prompt.c +++ b/Src/prompt.c @@ -270,7 +270,8 @@ zattrescape(zattr atr, int *len) } = /* Parse the argument for %H */ -static char * +/**/ +mod_export char * parsehighlight(char *arg, char endchar, zattr *atr) { static int entered =3D 0; @@ -295,9 +296,9 @@ parsehighlight(char *arg, char endchar, zattr *atr) } else *atr =3D TXT_ERROR; if (ep) - *ep =3D endchar; + *ep++ =3D endchar; else - ep =3D strchr(arg, '\0') - 1; + ep =3D strchr(arg, '\0'); entered =3D 0; return ep; } @@ -635,6 +636,7 @@ putpromptchar(int doprint, int endchar) case 'H': if (bv->fm[1] =3D=3D '{') { bv->fm =3D parsehighlight(bv->fm + 2, '}', &atr); + --bv->fm; if (atr !=3D TXT_ERROR) { treplaceattrs(atr); applytextattributes(TSC_PROMPT);