[Pkg-zsh-devel] Bug#613162: zsh: Loading colors script fails, bad set of key/value pairs

Frank Terbeck ft at bewatermyfriend.org
Sun Feb 13 15:50:01 UTC 2011


Benjamin Peter wrote:
[...]
> (dedeibel at jet)(262/pts)(14:25:13.02.11)-
> (%:~)- print ${#color}
> 4

Yeah. I was a little quick about this. This only prints the number of
key-value pairs in the associative array. What we're actually looking
for is this:

% print ${#${(kv)color}}

In any case, `4' is too low a value. what does this print?

% printf '%s = '\''%s'\''\n' ${(kv)color} | sort

>
> (dedeibel at jet)(263/pts)(14:25:13.02.11)-
> (%:~)- (set -x; colors;) 2>&1 | cat -v
> +/bin/zsh:3> colors
> +colors:4> typeset -Ag color colour
> +colors:6> color=( 00 none 01 bold 02 faint 22 normal 03 standout 23
> no-standout 04 underline 24 no-underline 05 blink 25 no-blink 07
> reverse 27 no-reverse 08 conceal 28 no-conceal 30 black 40 bg-black 31
> red 41 bg-red 32 green 42 bg-green 33 yellow 43 bg-yellow 34 blue 44
> bg-blue 35 magenta 45 bg-magenta 36 cyan 46 bg-cyan 37 white 47
> bg-white 39 default 49 bg-default )
[...]
> Does this tell you anything?

Thanks, I'll take a look at it when I'm on the train.

> What exactly does ${(kv)color} access? Is kv a value?

Those flags are used to access the keys and values of an associative
array:

% foo=( bar baz beer booze zack zonk )
% print ${foo[zack]}
zonk
% print ${(k)foo}
zack bar beer
% print ${(v)foo}
zonk baz booze
% print ${(kv)foo}
zack zonk bar baz beer booze


The latter is used to initialise $colour (British) with the same values
as in $color (American).

Regards, Frank






More information about the Pkg-zsh-devel mailing list