diff --git a/Functions/Misc/colors b/Functions/Misc/colors index 8a0cec383..d5933c9a9 100644 --- a/Functions/Misc/colors +++ b/Functions/Misc/colors @@ -21,7 +21,7 @@ color=( 07 reverse 27 no-reverse # 07 standout 27 no-standout 08 conceal 28 no-conceal -# 09 strikethrough # 29 no-strikethrough + 09 strikethrough 29 no-strikethrough # Font selection: # 10 font-default @@ -51,9 +51,9 @@ color=( # 50 no-proportional # 51 border-rectangle # 52 border-circle -# 53 overline + 53 overline # 54 no-border -# 55 no-overline + 55 no-overline # 56 through 59 reserved # Ideogram markings: @@ -84,7 +84,11 @@ color=( # 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 +local k Pattern +local -a color_names +print -- "color_names: $color_names" +color_names=(${${${(Mk)color:#bg-*}:#*bright*}#*-}) # get all color names +print -- "color_names: $color_names" for k in ${(k)color}; do color[${color[$k]}]=$k; done # Add "fg-" keys for all the text colors, for clarity. @@ -105,15 +109,29 @@ for k in '' fg- bg-; do color[${k}bright-grey]=${color[${k}bright-gray]} done -colour=(${(kv)color}) # A case where ksh namerefs would be useful ... +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 +local lc=$'\e[' rc=m # Standard ANSI terminal escape values + +# Attributes typeset -Hg reset_color bold_color -reset_color="$lc${color[none]}$rc" -bold_color="$lc${color[bold]}$rc" +typeset -AHg attribute + +reset_color="$lc${color[none]}$rc" # legacy attributes so existing scripts +bold_color="$lc${color[bold]}$rc" # won't fail + +# Get list of all attributes, generate ANSI code for each and add to the +# associative array "attribute". +Pattern="${(j.|.)color_names}" +#for k in ${${(ok)color:#(<->|bg-|fg-|bright)*}:#(${(j.|.)~color_names})}; do +#for k in ${(ok)color:#(<->|bg-|fg-|bright)*}:#($~Pattern)})}; do +for k in ${(ok)color:#(<->|bg-|fg-|bright|$~Pattern)*}; do + attribute[$k]="$lc${color[$k]}$rc" +done +attribute[reset]=${attribute[none]} # add additional name reset(aka none) # Foreground