From 372555ff201bad639c4b50411293cfd872e31728 Mon Sep 17 00:00:00 2001 From: Paul Ackersviller Date: Sun, 4 Nov 2007 21:21:28 +0000 Subject: Merge of unposted: add several comments about other ANSI terminal attributes, cribbed from ECMA-48. --- Functions/Misc/colors | 188 +++++++++++++++++++++++++++++--------------------- 1 file changed, 109 insertions(+), 79 deletions(-) (limited to 'Functions') diff --git a/Functions/Misc/colors b/Functions/Misc/colors index 464260db0..bef93c8c3 100644 --- a/Functions/Misc/colors +++ b/Functions/Misc/colors @@ -1,85 +1,115 @@ -# Put standard ANSI color codes in environment for easy use -reset_color=$'\e[0m' -bold_color=$'\e[1m' +# Put standard ANSI color codes in shell parameters for easy use. +# Note that some terminals do not support all combinations. -# Foreground +typeset -Ag color colour -typeset -Ag fg -fg=( - grey $'\e[30m' - red $'\e[31m' - green $'\e[32m' - yellow $'\e[33m' - blue $'\e[34m' - magenta $'\e[35m' - cyan $'\e[36m' - white $'\e[37m' -) -fg_zzzz="$reset_color" - -typeset -Ag fg_no_bold -fg_no_bold=( - grey $'\e[0;30m' - red $'\e[0;31m' - green $'\e[0;32m' - yellow $'\e[0;33m' - blue $'\e[0;34m' - magenta $'\e[0;35m' - cyan $'\e[0;36m' - white $'\e[0;37m' -) -fg_no_bold_zzzz="$reset_color" - -typeset -Ag fg_bold -fg_bold=( - grey $'\e[1;30m' - red $'\e[1;31m' - green $'\e[1;32m' - yellow $'\e[1;33m' - blue $'\e[1;34m' - magenta $'\e[1;35m' - cyan $'\e[1;36m' - white $'\e[1;37m' +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 ) -fg_bold_zzzz="$reset_color" + +# 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 + +# Add "fg-" keys for all the text colors, for clarity. + +for k in ${color[(I)3?]}; do color[fg-${color[$k]}]=$k; done + +# 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]} + +# Assistance for the color-blind. + +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 -Ag bg -bg=( - grey $'\e[40m' - red $'\e[41m' - green $'\e[42m' - yellow $'\e[43m' - blue $'\e[44m' - magenta $'\e[45m' - cyan $'\e[46m' - white $'\e[47m' -) -bg_zzzz="$reset_color" - -typeset -Ag bg_no_bold -bg_no_bold=( - grey $'\e[0;40m' - red $'\e[0;41m' - green $'\e[0;42m' - yellow $'\e[0;43m' - blue $'\e[0;44m' - magenta $'\e[0;45m' - cyan $'\e[0;46m' - white $'\e[0;47m' -) -bg_no_bold_zzzz="$reset_color" - -typeset -Ag bg_bold -bg_bold=( - grey $'\e[1;40m' - red $'\e[1;41m' - green $'\e[1;42m' - yellow $'\e[1;43m' - blue $'\e[1;44m' - magenta $'\e[1;45m' - cyan $'\e[1;46m' - white $'\e[1;47m' -) -bg_bold_zzzz="$reset_color" +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 -- cgit 1.4.1