-
Notifications
You must be signed in to change notification settings - Fork 5
/
esccolorscomp
85 lines (70 loc) · 1.56 KB
/
esccolorscomp
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
#!/bin/bash
#17
NAMES=(Default Black DarkRed DarkGreen DarkYellow DarkBlue DarkMagenta DarkCyan Gray DarkGray Red Green Yellow Blue Magenta Cyan White)
FGROUND=("39" "30" "31" "32" "33" "34" "35" "36" "37" "1;30" "1;31" "1;32" "1;33" "1;34" "1;35" "1;36" "1;37")
BGROUND=(49 40 41 42 43 44 45 46 47)
#Reset code \x1b[0m
#Attributes 0-Default; 1-bold; 4-understrike; 7-inversing;
echoc() #Text, color, background, attributes
{
if [ -z "$2" ];then
echo "$1"
return
fi
if [ -t 1 ];then
E__="\x1b[${FGROUND[$2]}m"
if [ -n "$3" ];then
E__="$E__\x1b[${BGROUND[$3]}m"
fi
if [ -n "$4" ];then
E__="$E__\x1b[$4""m"
fi
echo -e "$E__$1\x1b[0m"
else
echo "$1"
fi
}
echocn() #Text, color, background, attributes
{
if [ -z "$2" ];then
echo -n "$1"
return
fi
if [ -t 1 ];then
E__="\x1b[${FGROUND[$2]}m"
if [ -n "$3" ];then
E__="$E__\x1b[${BGROUND[$3]}m"
fi
if [ -n "$4" ];then
E__="$E__\x1b[$4""m"
fi
echo -e -n "$E__$1\x1b[0m"
else
echo -n "$1"
fi
}
echo -e "Foreground color:\tBackground color:"
for N in {0..16}; do
if [ $N -eq 1 ];then #foreground
echocn "$N - ${NAMES[$N]}" $N 4
else
echocn "$N - ${NAMES[$N]}" $N
fi
echo -e -n "\t\t"
if [ $N -le 8 ];then
if [ $N -gt 1 ];then
echoc " ${NAMES[$N]} " 1 $N #background
else
echoc " ${NAMES[$N]} " 0 $N
fi
else
echo
fi
done
echo
echocn "Default" 0 0 0; echo -n " "
echocn "Bold" 0 0 1; echo -n " "
echocn "Understrike" 0 0 4; echo -n " "
echocn "Inversing" 0 0 7; echo -n " "
echo
echo