installer: extract color sequences definition

This commit is contained in:
Marc Cornellà 2016-05-29 08:15:40 +02:00
parent 62b8a70a7c
commit eb453c6570

View File

@ -1,10 +1,15 @@
main() {
# Use colors, but only if connected to a terminal, and that terminal
# supports them.
#!/bin/sh
# Set up color sequences
setup_color() {
if which tput >/dev/null 2>&1; then
ncolors=$(tput colors)
else
ncolors=0
fi
if [ -t 1 ] && [ -n "$ncolors" ] && [ "$ncolors" -ge 8 ]; then
# Only use colors if connected to a terminal that supports them
if [ -t 1 ] && [ $ncolors -ge 8 ]; then
RED="$(tput setaf 1)"
GREEN="$(tput setaf 2)"
YELLOW="$(tput setaf 3)"
@ -19,6 +24,10 @@ main() {
BOLD=""
NORMAL=""
fi
}
main() {
setup_color
# Only enable exit-on-error after the non-critical colorization stuff,
# which may fail on systems lacking tput or terminfo