Migration from old pyutilz package name (which, in turn, came from
[pyutils.git] / tests / color_vars.sh
1 # https://en.wikipedia.org/wiki/ANSI_escape_code
2 # https://coolors.co/aa4465-ec7632-dcd5a0-f9cb40-875f00-698c6e-0b3820-5fafff-2f5d9d-7f5e97
3
4 # Sets shell environment variables to code for ANSI colors.
5
6 # Attributes
7 export NORMAL='\e[0m'
8 export BOLD='\e[1m'
9 export ITALICS='\e[3m'
10 export UNDERLINE='\e[4m'
11 export STRIKETHROUGH='\e[9m'
12
13 # Foreground colors
14 export BLACK='\e[30m'
15 export BROWN='\e[38;2;135;95;0m'        #875F00
16 export BRIGHT_RED='\e[38;2;175;0;0m'
17 export LIGHT_RED='\e[38;2;170;68;101m'  #AA4465
18 export RED='\e[31m'
19 export DARK_RED='\e[38;5;52m'
20 export PINK='\e[38;2;231;90;124m'       #E75A7C
21 export ORANGE='\e[38;2;236;118;50m'     #EC7632
22 export YELLOW='\e[38;2;249;203;64m'     #F9CB40
23 export GOLD='\e[38;5;94m'
24 export GREEN='\e[38;2;105;140;110m'     #698C6E
25 export DARK_GREEN='\e[38;2;10;51;29m'   #0A331D
26 export TEAL='\e[38;5;45m'
27 export CYAN='\e[38;2;95;175;255m'       #5FAFFF
28 export BLUE='\e[38;2;47;93;157m'        #2F5D9D
29 export DARK_BLUE='\e[38;5;18m'
30 export MAGENTA='\e[38;2;170;68;101m'    #AA4465
31 export DARK_MAGENTA='\e[38;5;63m'
32 export PURPLE='\e[38;2;127;94;151m'     #7F5E97
33 export ON_PURPLE='\e[48;2;127;94;151m'  #7F5E97
34 export DARK_PURPLE='\e[38;5;56m'
35 export WHITE='\e[37m'
36 export LIGHT_GRAY='\e[38;2;25;25;25m'
37 export LGRAY='\e[38;2;25;25;25m'
38 export GRAY='\e[30m'
39
40 # 8-bit: As 256-color lookup tables became common on graphic cards,
41 # escape sequences were added to select from a pre-defined set of 256
42 # colors:
43 #
44 # ESC[ 38;5;⟨n⟩ m Select foreground color
45 # ESC[ 48;5;⟨n⟩ m Select background color
46 #   0-  7:  standard colors (as in ESC [ 30–37 m)
47 #   8- 15:  high intensity colors (as in ESC [ 90–97 m)
48 #  16-231:  6 × 6 × 6 cube (216 colors): 16 + 36 × r + 6 × g + b (0 ≤ r, g, b ≤ 5)
49 # 232-255:  grayscale from black to white in 24 steps
50 function make_fg_color() {
51     if [ $# -ge 3 ]; then
52         if [ "$1" -gt "5" ] || [ "$2" -gt "5" ] || [ "$3" -gt "5" ]; then
53             echo -ne "\e[38;2;$1;$2;$3m"
54         else
55             N=$(( 16 + 36 * $1 + 6 * $2 + $3 ))
56             echo -ne "\e[38;5;${N}m"
57         fi
58     elif [ $# -eq 2 ]; then
59         N=$(( 16 + 36 * 0 + 6 * $1 + $2 ))
60         echo -ne "\e[38;5;${N}m"
61     elif [ $# -eq 1 ]; then
62         echo -ne "\e[38;5;$1m"
63     else
64         echo -ne ${LIGHT_GRAY}
65     fi
66 }
67
68 function make_bg_color() {
69     if [ $# -ge 3 ]; then
70         if [ "$1" -gt "5" ] || [ "$2" -gt "5" ] || [ "$3" -gt "5" ]; then
71             echo -ne "\e[48;2;$1;$2;$3m"
72         else
73             N=$(( 16 + 36 * $1 + 6 * $2 + $3 ))
74             echo -ne "\e[48;5;${N}m"
75         fi
76     elif [ $# -eq 2 ]; then
77         N=$(( 16 + 36 * 0 + 6 * $1 + $2 ))
78         echo -ne "\e[48;5;${N}m"
79     elif [ $# -eq 1 ]; then
80         echo -ne "\e[48;5;$1m"
81     else
82         echo -ne ${ON_GRAY}
83     fi
84 }
85
86 # Backgrounds
87 export ON_BLACK='\e[40m'
88 export ON_LGRAY='\e[48;2;25;25;25m'
89 export ON_RED='\e[41m'
90 export ON_ORANGE='\e[48;2;236;118;50m'
91 export ON_GREEN='\e[48;2;105;140;110m'
92 export ON_YELLOW='\e[48;2;249;203;64m'
93 export ON_BLUE='\e[48;2;47;93;157m'
94 export ON_MAGENTA='\e[48;2;170;68;101m'
95 export ON_CYAN='\e[48;2;95;175;255m'
96 export ON_WHITE='\e[47m'
97 export ON_DARK_PURPLE='\e[48;5;56m'
98
99 # Cursor color
100 export CURSOR='\e[38;5;208m'          # ORANGY
101 export ON_CURSOR='\e[48;5;208m'
102
103 # Reset sequence
104 export NC="\e[0m"                     # color reset