Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: coloring substitution seems to eat next line.
- X-seq: zsh-users 28361
- From: Ray Andrews <rayandrews@xxxxxxxxxxx>
- To: zsh-users@xxxxxxx
- Subject: Re: coloring substitution seems to eat next line.
- Date: Thu, 10 Nov 2022 11:28:04 -0800
- Archived-at: <https://zsh.org/users/28361>
- In-reply-to: <CAH+w=7a5hsJ3N1T3iQJMnNLttB3wFrZVTqPtg5Sjh5TTY0Fi_A@mail.gmail.com>
- List-id: <zsh-users.zsh.org>
- References: <c87afbb9-d8d1-1d9f-09a3-0e4172fe080f@eastlink.ca> <CAN=4vMp6wFY5MG5dOgWRTqc3W1OvhKsU=bbWZyR=yZgNKt3rRw@mail.gmail.com> <549715c2-8b36-8b7e-e3ac-cac02f43dd0f@eastlink.ca> <CAN=4vMoDkfG=SgpLjreoWZhwrhfEucGgeiKoRXB+ZQgi=nHohA@mail.gmail.com> <CAH+w=7a5hsJ3N1T3iQJMnNLttB3wFrZVTqPtg5Sjh5TTY0Fi_A@mail.gmail.com>
On 2022-11-10 10:54, Bart Schaefer wrote:
cc[42]="foo bar"
cc[42]=(foo bar)
The first one resets cc[42]. The second one both updates cc[42] and
inserts a new cc[43] after it.
Now there's a surprise. Nuts, that explains the weird output and the
seemingly empty next element. It bleeding creates a new empty next
element!! I'll leave it to more adept people to understand why that's
ever wanted.
Anyway, I stopped slicing (or did I start slicing? ...) anyway:
cc[$aa]=( ${cc[$aa]/(#b)((#i)$filter)/$'\e['$color;1m${match[1]}$'\e[0m'} )
... is the now slightly understandable strange output and ...
cc[$aa]=${cc[$aa]/(#b)((#i)$filter)/$'\e['$color;1m${match[1]}$'\e[0m'}
... works just fine :-) I've gotten into the habit of always using the
parentheses just because.
There is also the form
cc[42,44]=(foo bar)
which removes three elements (42,43,44) and replaces them with two new
ones (42 and 43). Hence a "slice".
Sheesh. So it looks like I stopped slicing. But that just above is
sorta understandable.
BTW I'm not using Roman's '(#M)' syntax because it seems to want to
print all sorts of values to the terminal. Like '$MATCH' is some
internal variable that always prints itself or something.
One last issue, tinkering with the code even as I compose this:
cc[$aa]=${cc[$aa]/(#b)(${zsh_case}${filter})/$'\e['$color;1m${match[1]}$'\e[0m'}
... the one thing left is to insert '$zsh_case' in there, which so far
is not working. But Roman has the answer:
cc[$aa]=${cc[$aa]/(#b)($~zsh_case${filter})/$'\e['$color;1m${match[1]}$'\e[0m'}
... I have not idea what '$~' means, but it works.
BTW, to my surprise, using native code gives the same performance as
using grep, 40 seconds on a stress test here. sed wanted 43 seconds.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author