Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: What appears to be inconsistent results from ${(%):-%F{${subscript}}
On 3/4/24, Jim <linux.tech.guy@xxxxxxxxx> 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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author