/
colortest
executable file
·70 lines (66 loc) · 1.85 KB
/
colortest
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
#!/bin/sh
color_escape () {
printf '\e[%sm' "$1"
}
get_at() {
case $1 in
normal) echo 00;;
bold) echo 01;;
italic) echo 03;;
blink) echo 05;;
underscore) echo 04;;
reverse) echo 07;;
concealed) echo 08;;
esac
}
get_bg() {
case $1 in
black) echo 40;;
red) echo 41;;
green) echo 42;;
yellow) echo 43;;
blue) echo 44;;
magenta) echo 45;;
cyan) echo 46;;
white) echo 47;;
default) echo 49;;
esac
}
get_fg() {
case $1 in
black) echo 30;;
red) echo 31;;
green) echo 32;;
yellow) echo 33;;
blue) echo 34;;
magenta) echo 35;;
cyan) echo 36;;
white) echo 37;;
default) echo 39;;
esac
}
test -z "$*" && set -- normal bold italic blink underscore reverse concealed
for attribute; do
echo "# $attribute (with background colors): "
for background in default black red green yellow blue magenta cyan white default; do
printf ' '
for foreground in black red green yellow blue magenta cyan white default; do
color_escape "$(get_at "$attribute");$(get_bg "$background");$(get_fg "$foreground")"
printf '%s' "$foreground"
color_escape '0'
test "$foreground" = default || printf ' - '
done
echo
done
if test "$(tput colors)" -ge 256; then
echo "# $attribute (256 colors): "
for i in `seq 16 255`; do
test "$((($i+3) % 6))" -eq 1 && printf ' '
color_escape "$(get_at "$attribute");38;5;$i"
printf 'color=%3d' "$i"
color_escape '0'
test "$((($i+3) % 6))" -ne 0 && printf ' -- ' || printf '\n'
done
fi
test $# -eq 1 || echo
done