zsh-users
 help / color / mirror / code / Atom feed
From: Roman Perepelitsa <roman.perepelitsa@gmail.com>
To: Ray Andrews <rayandrews@eastlink.ca>
Cc: Zsh Users <zsh-users@zsh.org>
Subject: Re: coloring substitution seems to eat next line.
Date: Thu, 10 Nov 2022 09:02:19 +0100	[thread overview]
Message-ID: <CAN=4vMp6wFY5MG5dOgWRTqc3W1OvhKsU=bbWZyR=yZgNKt3rRw@mail.gmail.com> (raw)
In-Reply-To: <c87afbb9-d8d1-1d9f-09a3-0e4172fe080f@eastlink.ca>

On Thu, Nov 10, 2022 at 1:44 AM Ray Andrews <rayandrews@eastlink.ca> wrote:
>
>      cc[$aa]=$( print -r $cc[$aa] | sed -rn
> "s/($filter)/\x1b\[$color;1m\1\x1b\[0m/${sed_case}gp" )
>
> ... that's the sed version working fine.  But this:
>
>      cc[aa]=(
> ${${cc[aa]}//(#b)((#i)${filter})/$'\e[31;1m'${match[1]}$'\e[0m'} )

Differences in the second version compared to the first:

- aa instead of $aa
- slice assignment instead of scalar (almost certainly unintended)
- hardcoded (#i) instead of $sed_case
- hardcoded 31 instead of $color
- $filter treated as a literal instead of regex

Given that the second version works without errors, I assume that cc
must be a regular (not associative) array. This means you can replace
the whole loop with this:

  local MATCH MBEGIN MEND
  cc=(${cc//(#m)$~zsh_case$filter/$'\e[31;1m'$MATCH$'\e[0m'})

Here's a test:

  () {
    emulate -L zsh -o extended_glob
    local cc=(/foo/Zsh/bar /baz /ZSHzsh /zsh-zsh)
    local filter=zsh
    local zsh_case='(#i)'
    local MATCH MBEGIN MEND
    cc=(${cc//(#m)$~zsh_case$filter/$'\e[31;1m'$MATCH$'\e[0m'})
    print -rC1 -- ${(qqqq)cc}
    print -rC1 -- $cc
  }

> /aWorking/Zsh                            disappears going in but seems
> to be there going out , but not colored

You can debug this by printing all relevant parameters.

    print -r -- "going in: $cc[aa]"
    typeset -p cc aa filter
    ...
    typeset -p cc
    print -r -- "coming out: $cc[aa]"

After that you can reproduce and dissect the issue in isolation. You
can also ask other people for help and give them everything they need
to reproduce the problem.

Roman.


  reply	other threads:[~2022-11-10  8:09 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-10  0:43 Ray Andrews
2022-11-10  8:02 ` Roman Perepelitsa [this message]
2022-11-10 18:25   ` Ray Andrews
2022-11-10 18:36     ` Roman Perepelitsa
2022-11-10 18:45       ` Ray Andrews
2022-11-10 18:54       ` Bart Schaefer
2022-11-10 19:28         ` Ray Andrews
2022-11-10 20:22           ` Bart Schaefer
2022-11-10 21:42             ` Ray Andrews
2022-11-10 21:51               ` Roman Perepelitsa
2022-11-11 17:24                 ` Ray Andrews
2022-11-10 22:47               ` Bart Schaefer
2022-11-10 23:07                 ` Ray Andrews
2022-11-10 23:27                   ` Bart Schaefer
2022-11-11 15:00                     ` Ray Andrews
2022-11-11 18:15                       ` Bart Schaefer
2022-11-11 18:50                         ` Ray Andrews
2022-11-11 19:25                           ` Bart Schaefer
2022-11-11 21:26                             ` Ray Andrews
2022-11-12  4:24                               ` Bart Schaefer
2022-11-12 14:03                                 ` Ray Andrews
2022-11-13 15:09                                   ` Ray Andrews
2022-11-14 14:12                                     ` Roman Perepelitsa
2022-11-14 17:08                                     ` Ray Andrews
2022-11-14 17:12                                       ` Roman Perepelitsa
2022-11-14 18:58                                         ` Ray Andrews
2022-11-14 20:00                                           ` Bart Schaefer
2022-11-14 23:25                                             ` Ray Andrews
2022-11-15 14:17                                               ` Belaboring substitution syntax Ray Andrews
2022-11-16  1:49                                                 ` Bart Schaefer
2022-11-16  2:54                                                   ` Ray Andrews
2022-11-16  6:26                                                     ` Bart Schaefer
2022-11-16 14:08                                                       ` Ray Andrews
2022-11-16 14:13                                                         ` Roman Perepelitsa
2022-11-17  2:31                                                           ` Bart Schaefer
2022-11-17  8:59                                                             ` Roman Perepelitsa
2022-11-17 16:02                                                               ` Ray Andrews
2022-11-16 20:46                                                       ` Ray Andrews
2022-11-16 10:32                                                   ` Roman Perepelitsa

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAN=4vMp6wFY5MG5dOgWRTqc3W1OvhKsU=bbWZyR=yZgNKt3rRw@mail.gmail.com' \
    --to=roman.perepelitsa@gmail.com \
    --cc=rayandrews@eastlink.ca \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).