Use color function instead of harcoding escape sequences

This commit is contained in:
Dylan 2016-03-29 21:04:31 +11:00
parent c9bb5988da
commit bfac607589
1 changed files with 24 additions and 29 deletions

View File

@ -2311,54 +2311,49 @@ colors () {
}
setcolors () {
c1="\033[0m\033[3${1}m"
c2="\033[0m\033[3${2}m"
c3="\033[0m\033[3${3}m"
c4="\033[0m\033[3${4}m"
c5="\033[0m\033[3${5}m"
c6="\033[0m\033[3${6}m"
# Fix for white on white
[ "$1" == 7 ] && c1="\033[0m"
[ "$2" == 7 ] && c2="\033[0m"
[ "$3" == 7 ] && c3="\033[0m"
[ "$4" == 7 ] && c4="\033[0m"
[ "$5" == 7 ] && c5="\033[0m"
[ "$6" == 7 ] && c6="\033[0m"
c1="$(color $1)"
c2="$(color $2)"
c3="$(color $3)"
c4="$(color $4)"
c5="$(color $5)"
c6="$(color $6)"
if [ "${colors[0]}" == "distro" ]; then
title_color="\033[0m\033[3${1}m"
title_color="$c1"
at_color="\033[0m"
underline_color="\033[0m"
subtitle_color="\033[0m\033[3${2}m"
subtitle_color="$c2"
colon_color="\033[0m"
info_color="\033[0m"
# If the second color is white use the first for the subtitle
[ "$2" == 7 ] && subtitle_color="\033[0m\033[3${1}m"
[ "$1" == 7 ] && title_color="\033[0m"
else
title_color="\033[0m\033[3${colors[0]}m"
at_color="\033[0m\033[3${colors[1]}m"
underline_color="\033[0m\033[3${colors[2]}m"
subtitle_color="\033[0m\033[3${colors[3]}m"
colon_color="\033[0m\033[3${colors[4]}m"
info_color="\033[0m\033[3${colors[5]}m"
title_color="$(color ${colors[0]})"
at_color="$(color ${colors[1]})"
underline_color="$(color ${colors[2]})"
subtitle_color="$(color ${colors[3]})"
colon_color="$(color ${colors[4]})"
info_color="$(color ${colors[5]})"
fi
[ "$progress_color_elapsed" == "distro" ] && \
progress_color_elapsed="7"
progress_color_elapsed="$(color 7)"
if [ "$progress_color_total" == "distro" ]; then
progress_color_total="$1"
progress_color_total="$c1"
case "$1" in
7 | 3 | 6) progress_color_total="${2}" ;;
7 | 3 | 6) progress_color_total="$c2" ;;
esac
fi
}
color () {
printf "%b%s" "\033[0m\033[3${1}m"
if [ "$1" == 7 ]; then
printf "%b%s" "\033[0m"
else
printf "%b%s" "\033[0m\033[3${1}m"
fi
}
@ -2466,8 +2461,8 @@ bar() {
total=$(printf %"$((progress_length - elapsed))"s)
# Set the colors and swap the spaces for $progress_char
bar="\033[0m\033[3${progress_color_elapsed}m${prog// /$progress_char}"
bar+="\033[0m\033[3${progress_color_total}m${total// /$progress_char}"
bar="${progress_color_elapsed}${prog// /$progress_char}"
bar+="${progress_color_total}${total// /$progress_char}"
printf "%b%s\n" "${bar}${clear}"
}