zsh-workers
 help / color / mirror / code / Atom feed
From: Mikael Magnusson <mikachu@gmail.com>
To: linuxtechguy@gmail.com
Cc: devs <zsh-workers@zsh.org>
Subject: Re: What appears to be inconsistent results from ${(%):-%F{${subscript}}
Date: Mon, 4 Mar 2024 19:06:12 +0100	[thread overview]
Message-ID: <CAHYJk3TCg14JgWYoz8mP22WWkxv-HyGCSkkLyAPVpRuGMhNmWQ@mail.gmail.com> (raw)
In-Reply-To: <CA+rB6GLO6B8kx95tPTdFzhwhE+yYk4o2AY64TRnj2FgbeLeibQ@mail.gmail.com>

On 3/4/24, Jim <linux.tech.guy@gmail.com> wrote:
> Hi all,
>
> Output for the  following function will help visualize what I believe to be
> inconsistencies of the output of ${(%):-%F{${subscript}}.
> I would assume %B (background) would yield similar results.
>
> Note the function outputs a solid block character in color.
> Hopefully the block charcter will cut and paste correctly.
>
> color_conversion_check () {
>   local subscript colorconversion
>   local subscripts
>   subscripts=(black blue cyan default gray green grey magenta red white
> yellow
>   bright-blue bright-cyan bright-gray bright-green bright-grey
> bright-magenta
>   bright-red bright-white bright-yellow
>   0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
>   16 17 18 229 230 231
>   232 233 234 253 254 255
>   '#000000' '#007fff' '#ff0080' '#abcdef' '#007FFF' '#FF0080' '#ABCDEF'
>   )
>   print -- "Output of fg associative array"
>   print --  "${fg[gray]}${(r.24..█.)}\e[0m  ${(V)fg[gray]}  fg[gray]"
>   print --  "${fg[grey]}${(r.24..█.)}\e[0m  ${(V)fg[grey]}  fg[grey]"
>   print --
>   for subscript ($subscripts) {
>     colorconversion="${(%):-%F{${subscript}}"
>     print -- "${(%)colorconversion}${(r.24..█.)}\e[0m
>  ${(V)colorconversion}  ${subscript}"
>   }
> }
>
> First, '${(%):-%F{${subscript}}' has unbalanced curly brackets({}), but
> still works.
> Adding a closing bracket(}) results in '}' being added to the output. So
> instead of
> getting ',,,m' you get '...m}'.  I'm confused. What am I missing?

This is a common-ish pitfall. When in double quotes, { and } are not
special to the shell, so the first } matches the opening { from ${.
You then have an extraneous } which is printed as normal.

> To my original point
>
> 1)  the color names grey and gray do not output black but output the
> default

The available colors are: black, red, green, yellow, blue, magenta,
cyan and white.

> 2) bright color names are not converted but output the default color
>     Should bright color names be added to the code?

ANSI only guarantees 8 colors are available.

> 3) using decimal numbers(0-255)
>     0 - 15  uses 30-27 and 90-97(bright) instead of using the colors
> defined
>    by the terminal
>   NOTE: 0-15 are defined even for TERM=linux
>   16-255 uses the colors defined by the terminal
>   Is there a reason why it doesn't use the terminal colors for 0-15?

I have no idea what you mean by this.

-- 
Mikael Magnusson


  parent reply	other threads:[~2024-03-04 18:06 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-04 14:56 Jim
2024-03-04 15:07 ` Jim
2024-03-04 18:06 ` Mikael Magnusson [this message]
2024-03-04 22:28 ` Bart Schaefer
2024-03-04 22:50 ` Oliver Kiddle

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=CAHYJk3TCg14JgWYoz8mP22WWkxv-HyGCSkkLyAPVpRuGMhNmWQ@mail.gmail.com \
    --to=mikachu@gmail.com \
    --cc=linuxtechguy@gmail.com \
    --cc=zsh-workers@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).