-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcolortest
158 lines (130 loc) · 6.54 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
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
#!/bin/bash
# Demo for using color codes in your scripts
# Looks best with white text on black background
# To learn more about tput https://www.gnu.org/software/termutils/manual/termutils-2.0/html_chapter/tput_1.html
# In this example we use tput codes (right side) but you can use ansi codes as well
# such as printf "\033[38;5;130mHello\033[0m\n" <--- prints "Hello" in brown with a mew line
# Above, the 38 5 130 are the ansi codes (left side) we printed out, \n is a new line
#------------------------------------------////
# Loop to list all the Ansi & tput color codes:
#------------------------------------------////
for color in {0..255}; do # Set Loop to 256 times
tput setaf "${color}" # Set the color
tput setaf "${color}" | command cat -v # Get the Ansi color code and print it in its color
tput rev "${color}" # Highlight the tput code portion of text
tput smul # Underline tput code portion of text
printf "%b\n" " tput code "${color}"" # Display the Highlighted and Underlined tput code text
tput sgr0 # Reset tput cursor attributes to normal
done
#------------------------------------------////
# Assign the "color name" as a variable:
# Change Color Numbers to your liking:
#------------------------------------------////
black=$(tput setaf 16)
white=$(tput setaf 15)
gray=$(tput setaf 240)
blue=$(tput setaf 21)
green=$(tput setaf 28)
red=$(tput setaf 1)
cyan=$(tput setaf 36)
purple=$(tput setaf 128)
brown=$(tput setaf 130)
yellow=$(tput setaf 226)
orange=$(tput setaf 202)
pink=$(tput setaf 207)
lgray=$(tput setaf 246)
lblue=$(tput setaf 39)
lgreen=$(tput setaf 118)
lred=$(tput setaf 9)
lcyan=$(tput setaf 14)
lpurple=$(tput setaf 99)
bold=$(tput bold)
blink=$(tput blink) # Blinking test
reverse=$(tput rev) # reverse video mode
normal=$(tput sgr0)
blgray=$(tput setab 246)
# ^ Background Light Gray. setab (background) instead of setaf (foreground)
#------------------------------------------////
# Array Using the Color Variables:
#------------------------------------------////
array=(
"${black}" "############" "${reverse}"" Black ""${normal}" "${black}" "############" "${white}" "<----- Black\n"
"${white}" "############" "${reverse}"" White ""${normal}" "${white}" "############" "${black}" "<----- White\n"
"${gray}" "############" "${reverse}"" Gray ""${normal}" "${gray}" "############\n"
"${blue}" "############" "${reverse}"" Blue ""${normal}" "${blue}" "############\n"
"${green}" "############" "${reverse}"" Green ""${normal}" "${green}" "############\n"
"${red}" "############" "${reverse}"" Red ""${normal}" "${red}" "############\n"
"${cyan}" "############" "${reverse}"" Cyan ""${normal}" "${cyan}" "############\n"
"${purple}" "############" "${reverse}"" Purple ""${normal}" "${purple}" "############\n"
"${brown}" "############" "${reverse}"" Brown ""${normal}" "${brown}" "############\n"
"${yellow}" "############" "${reverse}"" Yellow ""${normal}" "${yellow}" "############\n"
"${orange}" "############" "${reverse}"" Orange ""${normal}" "${orange}" "############\n"
"${pink}" "############" "${reverse}"" Pink ""${normal}" "${pink}" "############\n"
"${lgray}" "############" "${reverse}"" Light Gray ""${normal}" "${lgray}" "############\n"
"${lblue}" "############" "${reverse}"" Light Blue ""${normal}" "${lblue}" "############\n"
"${lgreen}" "############" "${reverse}"" Light Green ""${normal}" "${lgreen}" "############\n"
"${lred}" "############" "${reverse}"" Light Red ""${normal}" "${lred}" "############\n"
"${lcyan}" "############" "${reverse}"" Light Cyan ""${normal}" "${lcyan}" "############\n"
"${lpurple}" "############" "${reverse}"" Light Purple ""${normal}" "${lpurple}" "############\n"
"${normal}" "############" "${reverse}"" Normal ""${normal}" "${normal}" "############\n"
"${red}" "############" "${white}""${reverse}""${blink}" " Blink ""${normal}" "${blue}""############\n"
)
#------------------------------------------////
# Here Doc Banner
#------------------------------------------////
printf "%b\n" "${yellow}" # Banner Text Color
command cat << 'EOF'
____ ___ _ ___ ____ ____ _____ __ __ ___
/ ___/ _ \| | / _ \| _ \ | _ \| ____| \/ |/ _ \
| | | | | | | | | | | |_) | | | | | _| | |\/| | | | |
| |__| |_| | |__| |_| | _ < | |_| | |___| | | | |_| |
\____\___/|_____\___/|_| \_\ |____/|_____|_| |_|\___/
EOF
#------------------------------------------////
# Print the Array for Demo:
#------------------------------------------////
printf "%b\n" "${normal}"
printf "%b" "${array[@]}"
printf "%b" "${normal}" "\n"
#------------------------------------------////
# Print as a single line in multiple colors
# Like you might use in a script:
#------------------------------------------////
printf "%b\n" ""${red}" Combine colors "${white}"on the "${reverse}""${blue}"same line\n"
printf "%b" "${normal}"
#------------------------------------------////
# tput example to remove a section of the screen
# Like you might use in a script:
#------------------------------------------////
printf "%b" "${normal}" "tput is a powerful cursor managment tool." "\n\n"
printf "%b\n\n" " In addition to colors you can even clear certain portions of the screen"
tput civis # invisable cursor
read -n 1 -s -p "Press a key to try it"
#------------------------------------------////
# Remove
#------------------------------------------////
tput cuu 28 # move cursor up
tput ed # Clear to end of display
printf "%b\n"
printf "%b" "Or Replace it\n\n"
read -n 1 -s -p "Press a key to try it"
#------------------------------------------////
# Replace
#------------------------------------------////
tput cuu 3 # move cursor up
printf "%b\n"
tput ed # Clear to end of display
printf "%b" "${array[@]}\n" # Reprint the array on the desired section
printf "%b" ""${red}" Combine colors "${white}"on the "${reverse}""${blue}"same line\n" # not part of the array so display again
printf "%b" "${normal}"
tput ed # Clear to end of display
printf "%b\n"
#------------------------------------------////
# Here Doc Info
#------------------------------------------////
# not part of the array so display again
command cat << 'EOF'
To learn more about tput visit
https://www.gnu.org/software/termutils/manual/termutils-2.0/html_chapter/tput_1.html
EOF
tput sgr0 # Reset tput cursor attributes to normal