Hi Frank,
On 02/13/2011 04:50 PM, Frank Terbeck wrote:
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
Not sure if this does what it was inteded to.
$ printf '%s = '\''%s'\''\n' ${(kv)color} | sort
= ''''''
' ${(kv)color} | sortnone = ''
When I just do the following I get
$ print ${(kv)color}
none
But I think I figured what you wanted.
Maybe this?
printf '%s = %s\n' ${(kv)color[*]} | sort
Anyway. I tried to to do some kind of single step printf debugging after
your printf hints and added the files as an attachement. I hope it might
be usefull to you, I just see there that the mapping at some point
fails, and bg-blue seems to be associated with fg-red. "bg-blue =
fg-red". Maybe some loop is missing a value and leads to an "uneven
association".
What I did:
I added some printfs to the colors function.
called
$ unset -f colors
$ autoload -U colors
$ colors
and grabbed the ouput.
I fear the line numbers are rubbish but you can see the place in the
colors file.
Thanks, I'll take a look at it when I'm on the train.
Godspeed.
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
Thanks for the insight. I get it.
The latter is used to initialise $colour (British) with the same values
as in $color (American).
You just got to love it when you have to solve those kind of problems in IT.
regards,
Benjamin.
line 65 after init
00 = none
01 = bold
02 = faint
03 = standout
04 = underline
05 = blink
07 = reverse
08 = conceal
22 = normal
23 = no-standout
24 = no-underline
25 = no-blink
27 = no-reverse
28 = no-conceal
30 = black
31 = red
32 = green
33 = yellow
34 = blue
35 = magenta
36 = cyan
37 = white
39 = default
40 = bg-black
41 = bg-red
42 = bg-green
43 = bg-yellow
44 = bg-blue
45 = bg-magenta
46 = bg-cyan
47 = bg-white
49 = bg-default
line 78 after black and white mapping stuff
00 = none
22 = normal
44 = bg-blue
bg-black = 41
bg-blue = 01
bg-cyan = 03
bg-default = 28
bg-green = 43
bg-magenta = 02
bg-red = 42
bg-white = 04
bg-yellow =
black = 31
blink = 27
blue = 35
bold = 23
conceal = 30
cyan = 37
default = 40
faint = 24
green = 33
magenta = 36
no-blink = 47
no-conceal = 07
no-reverse = 49
no-standout = 45
no-underline = 46
red = 32
reverse = 08
standout = 25
underline = 05
white = 39
yellow = 34
line 80 after adding fg keys
00 = none
22 = normal
30 = fg-green
31 = 01
32 = fg-default
33 = fg-white
34 = 40
35 = 39
36 = 41
37 = fg-blue
39 = 30
44 = bg-blue
bg-black = fg-cyan
bg-blue = fg-red
bg-cyan = 03
bg-default = 28
bg-green = 43
bg-magenta = 02
bg-red = 42
bg-white = 04
bg-yellow =
black = 31
blink = 27
blue = 35
bold = 23
conceal = fg-black
cyan = 37
default = fg-yellow
faint = 24
green = 33
magenta = 36
no-blink = 47
no-conceal = 07
no-reverse = 49
no-standout = 45
no-underline = 46
red = 32
reverse = 08
standout = 25
underline = 05
white = fg-magenta
yellow = 34
line 90 after prompt theme color setting and before error
00 = none
22 = normal
30 = black
30 = fg-green
31 = 01
31 = red
32 = green
32 = grey
33 = fg-white
33 = yellow
34 = blue
34 = fg-grey
35 = magenta
36 = cyan
37 = fg-blue
37 = white
39 = default
40 = bg-black
41 = bg-red
42 = bg-green
43 = bg-yellow
44 = bg-blue
bg-blue = fg-red
bg-cyan = 03
bg-default = 28
bg-grey = fg-yellow
bg-magenta = 02
bg-white = 04
blink = 27
bold = 23
conceal = fg-black
faint = 24
fg-cyan = 36
fg-default = 39
fg-magenta = 35
no-blink = 47
no-conceal = 07
no-reverse = 49
no-standout = 45
no-underline = 46
reverse = 08
standout = 25
underline = 05
colors:103: bad set of key/value pairs for associative array
# Put standard ANSI color codes in shell parameters for easy use.
# Note that some terminals do not support all combinations.
typeset -Ag color colour
color=(
# Codes listed in this array are from ECMA-48, Section 8.3.117, p. 61.
# Those that are commented out are not widely supported or aren't closely
# enough related to color manipulation, but are included for completeness.
# Attribute codes:
00 none # 20 gothic
01 bold # 21 double-underline
02 faint 22 normal
03 standout 23 no-standout
04 underline 24 no-underline
05 blink 25 no-blink
# 06 fast-blink # 26 proportional
07 reverse 27 no-reverse
08 conceal 28 no-conceal
# 09 strikethrough # 29 no-strikethrough
# Font selection:
# 10 font-default
# 11 font-first
# 12 font-second
# 13 font-third
# 14 font-fourth
# 15 font-fifth
# 16 font-sixth
# 17 font-seventh
# 18 font-eighth
# 19 font-ninth
# Text color codes:
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
# 38 iso-8316-6 # 48 bg-iso-8316-6
39 default 49 bg-default
# Other codes:
# 50 no-proportional
# 51 border-rectangle
# 52 border-circle
# 53 overline
# 54 no-border
# 55 no-overline
# 56 through 59 reserved
# Ideogram markings:
# 60 underline-or-right
# 61 double-underline-or-right
# 62 overline-or-left
# 63 double-overline-or-left
# 64 stress
# 65 no-ideogram-marking
)
print "line 65 after init"
printf '%s = %s\n' ${(kv)color[*]} | sort
# A word about black and white: The "normal" shade of white is really a
# very pale grey on many terminals; to get truly white text, you have to
# use bold white, and to get a truly white background you have to use
# bold reverse white bg-xxx where xxx is your desired foreground color
# (and which means the foreground is also bold).
# Map in both directions; could do this with e.g. ${(k)colors[(i)normal]},
# but it's clearer to include them all both ways.
local k
for k in ${(k)color}; do color[${color[$k]}]=$k; done
print "line 78 after black and white mapping stuff"
printf '%s = %s\n' ${(kv)color[*]} | sort
# Add "fg-" keys for all the text colors, for clarity.
for k in ${color[(I)3?]}; do color[fg-${color[$k]}]=$k; done
print "line 80 after adding fg keys"
printf '%s = %s\n' ${(kv)color[*]} | sort
# This is inaccurate, but the prompt theme system needs it.
color[grey]=${color[black]}
color[fg-grey]=${color[grey]}
color[bg-grey]=${color[bg-black]}
print "line 90 after prompt theme color setting and before error"
printf '%s = %s\n' ${(kv)color[*]} | sort
# Assistance for the color-blind.
# This line crashes and does not work on my system! bpeter 2011-02-13
# bugreport filed #613162
colour=(${(kv)color}) # A case where ksh namerefs would be useful ...
# The following are terminal escape sequences used by colored prompt themes.
local lc=$'\e[' rc=m # Standard ANSI terminal escape values
typeset -Hg reset_color bold_color
reset_color="$lc${color[none]}$rc"
bold_color="$lc${color[bold]}$rc"
# Foreground
typeset -AHg fg fg_bold fg_no_bold
for k in ${(k)color[(I)fg-*]}; do
fg[${k#fg-}]="$lc${color[$k]}$rc"
fg_bold[${k#fg-}]="$lc${color[bold]};${color[$k]}$rc"
fg_no_bold[${k#fg-}]="$lc${color[normal]};${color[$k]}$rc"
done
# Background
typeset -AHg bg bg_bold bg_no_bold
for k in ${(k)color[(I)bg-*]}; do
bg[${k#bg-}]="$lc${color[$k]}$rc"
bg_bold[${k#bg-}]="$lc${color[bold]};${color[$k]}$rc"
bg_no_bold[${k#bg-}]="$lc${color[normal]};${color[$k]}$rc"
done