Merge pull request #197 from dylanaraps/color_func

Use color function instead of harcoding escape sequences
This commit is contained in:
Dylan Araps 2016-03-29 23:47:14 +11:00
commit b3dc18799c
1 changed files with 32 additions and 36 deletions

View File

@ -435,8 +435,7 @@ config_file="$HOME/.config/neofetch/config"
# Set no case match and extended globbing.
shopt -s nocasematch
shopt -s extglob
shopt -s nocasematch extglob
# Operating System {{{
@ -2306,54 +2305,51 @@ 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"
if [ "$progress_color_total" == "distro" ]; then
progress_color_total="$1"
case "$1" in
7 | 3 | 6) progress_color_total="${2}" ;;
esac
if [ "$progress_color_elapsed" == "distro" ]; then
progress_color_elapsed="$(color 7)"
else
progress_color_elapsed="$(color $progress_color_elapsed)"
fi
case "$progress_color_total $1" in
distro\ [736]) progress_color_total="$c2" ;;
distro\ [0-9]) progress_color_total="$c1" ;;
*) progress_color_total="$(color $progress_color_total)" ;;
esac
}
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
}
@ -2461,8 +2457,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}"
}