-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathansitest
executable file
·235 lines (207 loc) · 7.62 KB
/
ansitest
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
#!/bin/sh
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Copyright 2014 Jeremy Brubaker <jbru362@gmail.com>
#
# abstract: Test terminal ANSI escape capabilities
#
esc="\033["
show_normal () {
printf " BG Codes\n"
printf " FG -------------------------------------------------------------------------------\n"
if test $f_terminfo = 1; then
printf " Codes 49m 40m 41m 42m 43m 44m 45m 46m 47m\n"
else
printf " Codes 0 1 2 3 4 5 6 7\n"
fi
printf " --------------------------------------------------------------------------------------\n"
for fore in 39 $( seq 30 37 ); do
if test $f_terminfo = 1; then
line1=" ${fore}m "
line2=" 1;${fore}m "
else
line1=" $fore "
line2=" $fore,b "
fi
for back in 49 $( seq 40 47 ); do
line1="${line1}${esc}${back};${fore}m Normal ${esc}0m "
line2="${line2}${esc}${back};${fore};1m Bold ${esc}0m "
done
printf "$line1\n$line2\n"
done
printf "\n"
printf " Defaults\n"
printf " -----------------\n"
printf " m : ${esc}mNormal${esc}0m\t\n"
printf " 1m : ${esc}1mBold${esc}0m\n"
printf "\n"
printf "%s" "Example: printf \"\033[31;44m"
printf "${esc}31;44mRed text on blue${esc}0m"
printf "%s\n" "\033[0m\""
}
show_bright () {
printf " Hi Intensity High Intensity BG Codes\n"
printf " FG -------------------------------------------------------------------------------\n"
if test $f_terminfo = 1; then
printf " Codes 49m 100m 101m 102m 103m 104m 105m 106m 107m\n"
else
printf " Codes 8 9 10 11 12 13 14 15\n"
fi
printf " --------------------------------------------------------------------------------------\n"
for fore in 39 $( seq 30 37 ); do
line1=" ${fore}m "
line2=" 1;${fore}m "
for back in 49 $( seq 100 107 ); do
line1="${line1}${esc}${back};${fore}m Normal ${esc}0m "
line2="${line2}${esc}${back};${fore};1m Bold ${esc}0m "
done
printf "$line1\n$line2\n"
done
printf "\n"
printf " Defaults\n"
printf " -----------------\n"
printf " m : ${esc}mNormal${esc}0m\t\n"
printf " 1m : ${esc}1mBold${esc}0m\n"
printf "\n"
printf "%s" "Example: printf \"\033[31;104m"
printf "${esc}31;104mRed text on bright blue${esc}0m"
printf "%s\n" "\033[0m\""
}
show_formats () {
printf " Formatting Codes\t\tReset Codes\n"
printf " ----------------------------- -----------------------------------------\n"
printf " 1m : ${esc}1mBold${esc}0m\t2m : ${esc}2mDim${esc}0m"
printf "\t"
printf "21m : ${esc}1mBold ${esc}0moff\t\t22m : ${esc}2mDim${esc}22m off"
printf "\n"
printf " 3m : ${esc}3mItalic${esc}0m\t4m : ${esc}4mUnderline${esc}0m"
printf "\t"
printf "23m : ${esc}3mItalic${esc}23m off\t24m : ${esc}4mUnderline${esc}24m off"
printf "\n"
printf " 5m : ${esc}5mBlink${esc}0m\t6m : ${esc}6mBlink Fast${esc}0m"
printf "\t"
printf "25m : ${esc}5mBlink${esc}25m off"
printf "\n"
printf " 7m : ${esc}7mReverse${esc}0m\t8m : Hidden (${esc}8mx${esc}0m)"
printf "\t"
printf "27m : ${esc}7mReverse${esc}27m off\t28m : Hidden (${esc}28mx${esc}0m) off"
printf "\n"
printf " 9m : ${esc}9mStrikeout${esc}0m"
printf "\t\t\t"
printf "29m : ${esc}9mStrikeout${esc}29m off\t 0m : Reset all"
printf "${esc}0m\n"
printf "4:1m : ${esc}4:1mUnderline${esc}4:0m"
printf "\t"
printf "4:2m : ${esc}4:2mDouble Underline${esc}4:0m"
printf "\n"
printf "4:3m : ${esc}4:3mUndercurl${esc}4:0m"
printf "\t"
printf "4:4m : ${esc}4:4mDotted Undeline${esc}4:0m"
printf "\t"
printf "4:5m : ${esc}4:5mDashed Undeline${esc}4:0m"
printf "\n"
printf "4:0m : ${esc}4:0mNo underline${esc}4:0m\n"
printf "\n"
printf "%s" " Example: printf \"\033[1m"
printf "${esc}1mBold text${esc}0m"
printf "%s\n" "\033[0m\""
}
show_256 () {
printf " 256 Colors\n"
printf " ----------\n"
printf " 38;5;<n>m : Select foreground color\n"
printf " 48;5;<n>m : Select background color\n"
printf " 0- 7: Standard colors\n"
printf " 8- 15: High intensity colors\n"
printf " 16-231: 6x6x6 cube (216 colors)\n"
printf " 232-255: Grayscale (black to white)\n"
printf "\n"
printf " Example: printf \"\033[38;5;1;48;5;4m"
printf "${esc}38;5;1;48;5;4mRed text on blue${esc}0m"
printf "\033[0m\"\n"
printf "\n"
printf " Underline/Undercurl\n"
printf " -------------------\n"
printf " 58:5:<n>m : Select underline/undercurl color\n"
printf " 59m : Reset color\n"
printf "\n"
printf " Examples:\n"
printf " 4:1;58:5:199m : ${esc}4:1;58:5:199mPink underline${esc}4:0m\n"
printf " 4:3;58:5:199m : ${esc}4:3;58:5:199mPink undercurl${esc}4:0m\n"
printf " 4:3;59:bm : ${esc}4:3;59mReset colored${esc}4:0m\n"
}
show_24bit () {
printf " 24-bit Color\n"
printf " ------------\n"
printf " 38;2;<r>;<g>;<b>m : Select RGB foreground color\n"
printf " 48;2;<r>;<g>;<b>m : Select RGB background color\n"
printf " 232-255: Grayscale (black to white)\n"
printf "\n"
printf " Example: printf \"\033[38;2;255;0;0m\033[48;2;0;255;0m"
printf "${esc}38;2;255;0;0m${esc}48;2;0;0;255mRed text on blue${esc}0m"
printf "\033[0m\"\n"
printf "\n"
printf " Underline/Undercurl\n"
printf " -------------------\n"
printf " 58:2;<r>;<g>;<b>m : Select RGB underline/undercurl color\n"
printf " 59m : Reset color\n"
printf "\n"
printf " Examples:\n"
printf " 4:1;58:2:0:255:0m : ${esc}4:1;58:2:0:255:0mGreen underline${esc}4:0m\n"
printf " 4:3;58:2:255:0:0m : ${esc}4:3;58:2:255:0:0mRed undercurl${esc}4:0m"
printf "\n"
printf " 4:3;59m : ${esc}4:3;59mReset color${esc}4:0m\n"
}
# Process options {
print_help() {
cat <<EOF
Usage: ansitest [OPTION]
Display ANSI escape code help
-n display normal codes
-b display high-intensity codes
-f display formatting codes
-2 display 256 color codes
-t display 24-bit color codes
-T display terminfo(5) codes where available
-h display this help
EOF
}
f_default=1
f_normal=0
f_bright=0
f_formats=0
f_256=0
f_24bit=0
f_terminfo=0
while getopts "nbf2tTh" opt; do
case $opt in
n) f_normal=1; f_default=0 ;;
b) f_bright=1; f_default=0 ;;
f) f_formats=1; f_default=0 ;;
2) f_256=1; f_default=0 ;;
t) f_24bit=1; f_default=0 ;;
T) f_terminfo=1 ;;
h) print_help; exit ;;
*) print_help; exit ;;
esac
done
# }
test $f_normal = 1 ||
test $f_default = 1 && show_normal
test $f_bright = 1 && show_bright
test $f_formats = 1 && show_formats
test $f_256 = 1 && show_256
test $f_24bit = 1 && show_24bit
exit 0