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

View file

@ -435,8 +435,7 @@ config_file="$HOME/.config/neofetch/config"
# Set no case match and extended globbing. # Set no case match and extended globbing.
shopt -s nocasematch shopt -s nocasematch extglob
shopt -s extglob
# Operating System {{{ # Operating System {{{
@ -2306,54 +2305,51 @@ colors () {
} }
setcolors () { setcolors () {
c1="\033[0m\033[3${1}m" c1="$(color $1)"
c2="\033[0m\033[3${2}m" c2="$(color $2)"
c3="\033[0m\033[3${3}m" c3="$(color $3)"
c4="\033[0m\033[3${4}m" c4="$(color $4)"
c5="\033[0m\033[3${5}m" c5="$(color $5)"
c6="\033[0m\033[3${6}m" c6="$(color $6)"
# 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"
if [ "${colors[0]}" == "distro" ]; then if [ "${colors[0]}" == "distro" ]; then
title_color="\033[0m\033[3${1}m" title_color="$c1"
at_color="\033[0m" at_color="\033[0m"
underline_color="\033[0m" underline_color="\033[0m"
subtitle_color="\033[0m\033[3${2}m" subtitle_color="$c2"
colon_color="\033[0m" colon_color="\033[0m"
info_color="\033[0m" info_color="\033[0m"
# If the second color is white use the first for the subtitle # If the second color is white use the first for the subtitle
[ "$2" == 7 ] && subtitle_color="\033[0m\033[3${1}m" [ "$2" == 7 ] && subtitle_color="\033[0m\033[3${1}m"
[ "$1" == 7 ] && title_color="\033[0m"
else else
title_color="\033[0m\033[3${colors[0]}m" title_color="$(color ${colors[0]})"
at_color="\033[0m\033[3${colors[1]}m" at_color="$(color ${colors[1]})"
underline_color="\033[0m\033[3${colors[2]}m" underline_color="$(color ${colors[2]})"
subtitle_color="\033[0m\033[3${colors[3]}m" subtitle_color="$(color ${colors[3]})"
colon_color="\033[0m\033[3${colors[4]}m" colon_color="$(color ${colors[4]})"
info_color="\033[0m\033[3${colors[5]}m" info_color="$(color ${colors[5]})"
fi fi
[ "$progress_color_elapsed" == "distro" ] && \ if [ "$progress_color_elapsed" == "distro" ]; then
progress_color_elapsed="7" progress_color_elapsed="$(color 7)"
else
if [ "$progress_color_total" == "distro" ]; then progress_color_elapsed="$(color $progress_color_elapsed)"
progress_color_total="$1"
case "$1" in
7 | 3 | 6) progress_color_total="${2}" ;;
esac
fi 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 () { 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) total=$(printf %"$((progress_length - elapsed))"s)
# Set the colors and swap the spaces for $progress_char # Set the colors and swap the spaces for $progress_char
bar="\033[0m\033[3${progress_color_elapsed}m${prog// /$progress_char}" bar="${progress_color_elapsed}${prog// /$progress_char}"
bar+="\033[0m\033[3${progress_color_total}m${total// /$progress_char}" bar+="${progress_color_total}${total// /$progress_char}"
printf "%b%s\n" "${bar}${clear}" printf "%b%s\n" "${bar}${clear}"
} }