-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcolorsel
201 lines (177 loc) · 4.08 KB
/
colorsel
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
#!/bin/sh
# colorsel
# killer-app to make an ANSI attribute/color string -- bjd
# not all attributes are used here
# Note: TPUT must understand TERMINFO (not TERMCAP) capabilities -- acli
TPUT=tcput
# Try to detect the correct TPUT command.
# Real sh (e.g., Solaris sh) seem to print everything to stdout,
# but bash prints the not found message to stderr.
if type $TPUT 2>&1| grep 'not found' >/dev/null; then
for TPUT in tputs tput; do
type $TPUT 2>&1| grep 'not found' >/dev/null || break
done
fi
${TPUT} clear || exit 1
#echo -en "\033[H\033[J"
# attributes:
# 0 = all attributes off
# 1 = intensity 2 (bold)
# 2 = intensity 0 (half-bright)
# 4 = underline on
# 5 = blink on
# 7 = reverse on
# 10 = G0/G1 charset
# 11 = 1st alternate font
# 12 = 2nd alternate font
# 21 = intensity 1 (normal, default)
# 22 = intensity 1 (normal, default)
# 24 = underline off
# 25 = blink off
# 27 = reverse off
# 38 = default fg, white underline
# 39 = default fg, underline off
# 49 = default bg
error()
{
echo -en "\nError: $1"
ERROR=1
}
choose()
{
if [ ! "$4" = "-1" ]
then
PREV=$4
else
PREV=""
fi
${TPUT} cup $1 0
echo -en "Choose $3 number: $PREV" >&2
${TPUT} cup $1 $2
read answer
if [ "$answer" = "" ]
then
answer=$4
fi
if [ ! "$answer" = "-1" ]
then
${TPUT} cup $1 $2
echo $answer" "
fi
}
CHR="*"
echo -e "\n\t\t\t\tBJ's colorsel %^)"
echo -e "\n\n\t\t\t\t\tBG"
echo -e " black red green yellow blue magenta cyan white"
echo -e " 40 41 42 43 44 45 46 47"
for FG in 30 31 32 33 34 35 36 37
do
if [ $FG -eq 33 ]
then
echo -n "F $FG"
elif [ $FG -eq 34 ]
then
echo -n "G $FG"
else
echo -en " $FG"
fi
for BG in 40 41 42 43 44 45 46 47
do
echo -en "[${BG};${FG}m${CHR}[m"
echo -en "[1;${BG};${FG}m${CHR}[m"
echo -en "[1;4;${BG};${FG}m${CHR}[m"
echo -en "[1;4;7;${BG};${FG}m${CHR}[m"
echo -en "[1;7;${BG};${FG}m${CHR}[m"
echo -en "[2;${BG};${FG}m${CHR}[m"
echo -en "[2;4;${BG};${FG}m${CHR}[m"
echo -en "[2;4;7;${BG};${FG}m${CHR}[m"
echo -en "[2;7;${BG};${FG}m${CHR}[m"
#echo -en "[4;${BG};${FG}m${CHR}[m"
#echo -en "[4;7;${BG};${FG}m${CHR}[m"
done
echo
done
ATTR_NRS="012345678"
echo -e " ${ATTR_NRS}${ATTR_NRS}${ATTR_NRS}${ATTR_NRS}${ATTR_NRS}${ATTR_NRS}${ATTR_NRS}${ATTR_NRS}"
echo -e "\t\t\t\t ATTR"
BG="-1"
FG="-1"
AT="-1"
while [ 1 = 1 ]
do
ERROR=0
${TPUT} cup 19 0
#${TPUT} ed
choose 18 26 "background" $BG
BG=$answer
choose 19 26 "foreground" $FG
FG=$answer
choose 20 26 "attribute " $AT
AT=$answer
if [ ! $BG = -1 ]
then
if [ $BG -lt 40 -o $BG -gt 47 ]
then
error "background out of range (should be empty or [40-47])"
fi
fi
if [ ! $FG = -1 ]
then
if [ $FG -lt 30 -o $FG -gt 37 ]
then
error "foreground out of range (should be empty or [30-37])"
fi
fi
if [ ! $AT = -1 ]
then
if [ $AT -gt 8 ]
then
error "attribute choice out of range (should be empty or [0-8])"
fi
fi
if [ $ERROR -eq 0 ]
then
${TPUT} ed
echo -n "Combined string : "
SEP=";"
if [ "$AT" = "-1" ]; then STR=""; SEP="";
elif [ "$AT" = "0" ]; then STR="0";
elif [ "$AT" = "1" ]; then STR="1";
elif [ "$AT" = "2" ]; then STR="1;4";
elif [ "$AT" = "3" ]; then STR="1;4;7";
elif [ "$AT" = "4" ]; then STR="1;7";
elif [ "$AT" = "5" ]; then STR="2";
elif [ "$AT" = "6" ]; then STR="2;4";
elif [ "$AT" = "7" ]; then STR="2;4;7";
elif [ "$AT" = "8" ]; then STR="2;7";
#elif [ "$AT" = "9" ]; then# STR="4";
#elif [ "$AT" = "A" ]; then# STR="4;7";
fi
if [ ! "$BG" = "-1" ]
then
STR="${STR}${SEP}${BG}"
SEP=";"
fi
if [ ! "$FG" = "-1" ]
then
STR="${STR}${SEP}${FG}"
fi
echo ${STR}" "
if [ $ERROR -eq 1 ]
then
echo
fi
if [ ! "${STR}" = "" ]
then
STR="\033[${STR}m"
fi
echo -e "\n\n\nIs ${STR}this\033[m what you had in mind?"
echo -e "And then you could add a 5 attribute to make it \033[5m${STR}blink\033[m..."
echo -n "Again? "
read answer
if [ "$answer" = "n" -o "$answer = "N" -o "$answer = "no" ]
then
exit
fi
fi
done