From da05b8dbb8325a4be669686e2edc09602d08d58a Mon Sep 17 00:00:00 2001 From: Jim Myhrberg Date: Sat, 14 Mar 2015 13:03:52 +0000 Subject: [PATCH] Attempt to avoid tput errors. Should hopefully prevent issues like #19 in the future. --- colors.sh | 67 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 34 insertions(+), 33 deletions(-) diff --git a/colors.sh b/colors.sh index d4f48ae..448ad10 100644 --- a/colors.sh +++ b/colors.sh @@ -1,41 +1,42 @@ # Regular -txtblk="$(tput setaf 0)" # Black -txtred="$(tput setaf 1)" # Red -txtgrn="$(tput setaf 2)" # Green -txtylw="$(tput setaf 3)" # Yellow -txtblu="$(tput setaf 4)" # Blue -txtpur="$(tput setaf 5)" # Purple -txtcyn="$(tput setaf 6)" # Cyan -txtwht="$(tput setaf 7)" # White +txtblk="$(tput setaf 0 2>/dev/null || echo '\e[0;30m')" # Black +txtred="$(tput setaf 1 2>/dev/null || echo '\e[0;31m')" # Red +txtgrn="$(tput setaf 2 2>/dev/null || echo '\e[0;32m')" # Green +txtylw="$(tput setaf 3 2>/dev/null || echo '\e[0;33m')" # Yellow +txtblu="$(tput setaf 4 2>/dev/null || echo '\e[0;34m')" # Blue +txtpur="$(tput setaf 5 2>/dev/null || echo '\e[0;35m')" # Purple +txtcyn="$(tput setaf 6 2>/dev/null || echo '\e[0;36m')" # Cyan +txtwht="$(tput setaf 7 2>/dev/null || echo '\e[0;37m')" # White # Bold -bldblk="$(tput setaf 0)$(tput bold)" # Black -bldred="$(tput setaf 1)$(tput bold)" # Red -bldgrn="$(tput setaf 2)$(tput bold)" # Green -bldylw="$(tput setaf 3)$(tput bold)" # Yellow -bldblu="$(tput setaf 4)$(tput bold)" # Blue -bldpur="$(tput setaf 5)$(tput bold)" # Purple -bldcyn="$(tput setaf 6)$(tput bold)" # Cyan -bldwht="$(tput setaf 7)$(tput bold)" # White +bldblk="$(tput setaf 0 2>/dev/null)$(tput bold 2>/dev/null || echo '\e[1;30m')" # Black +bldred="$(tput setaf 1 2>/dev/null)$(tput bold 2>/dev/null || echo '\e[1;31m')" # Red +bldgrn="$(tput setaf 2 2>/dev/null)$(tput bold 2>/dev/null || echo '\e[1;32m')" # Green +bldylw="$(tput setaf 3 2>/dev/null)$(tput bold 2>/dev/null || echo '\e[1;33m')" # Yellow +bldblu="$(tput setaf 4 2>/dev/null)$(tput bold 2>/dev/null || echo '\e[1;34m')" # Blue +bldpur="$(tput setaf 5 2>/dev/null)$(tput bold 2>/dev/null || echo '\e[1;35m')" # Purple +bldcyn="$(tput setaf 6 2>/dev/null)$(tput bold 2>/dev/null || echo '\e[1;36m')" # Cyan +bldwht="$(tput setaf 7 2>/dev/null)$(tput bold 2>/dev/null || echo '\e[1;37m')" # White # Underline -undblk="$(tput setaf 0)$(tput smul)" # Black -undred="$(tput setaf 1)$(tput smul)" # Red -undgrn="$(tput setaf 2)$(tput smul)" # Green -undylw="$(tput setaf 3)$(tput smul)" # Yellow -undblu="$(tput setaf 4)$(tput smul)" # Blue -undpur="$(tput setaf 5)$(tput smul)" # Purple -undcyn="$(tput setaf 6)$(tput smul)" # Cyan -undwht="$(tput setaf 7)$(tput smul)" # White +undblk="$(tput setaf 0 2>/dev/null)$(tput smul 2>/dev/null || echo '\e[4;30m')" # Black +undred="$(tput setaf 1 2>/dev/null)$(tput smul 2>/dev/null || echo '\e[4;31m')" # Red +undgrn="$(tput setaf 2 2>/dev/null)$(tput smul 2>/dev/null || echo '\e[4;32m')" # Green +undylw="$(tput setaf 3 2>/dev/null)$(tput smul 2>/dev/null || echo '\e[4;33m')" # Yellow +undblu="$(tput setaf 4 2>/dev/null)$(tput smul 2>/dev/null || echo '\e[4;34m')" # Blue +undpur="$(tput setaf 5 2>/dev/null)$(tput smul 2>/dev/null || echo '\e[4;35m')" # Purple +undcyn="$(tput setaf 6 2>/dev/null)$(tput smul 2>/dev/null || echo '\e[4;36m')" # Cyan +undwht="$(tput setaf 7 2>/dev/null)$(tput smul 2>/dev/null || echo '\e[4;37m')" # White # Background -bakblk="$(tput setab 0)" # Black -bakred="$(tput setab 1)" # Red -bakgrn="$(tput setab 2)" # Green -bakylw="$(tput setab 3)" # Yellow -bakblu="$(tput setab 4)" # Blue -bakpur="$(tput setab 5)" # Purple -bakcyn="$(tput setab 6)" # Cyan -bakwht="$(tput setab 7)" # White +bakblk="$(tput setab 0 2>/dev/null || echo '\e[40m')" # Black +bakred="$(tput setab 1 2>/dev/null || echo '\e[41m')" # Red +bakgrn="$(tput setab 2 2>/dev/null || echo '\e[42m')" # Green +bakylw="$(tput setab 3 2>/dev/null || echo '\e[43m')" # Yellow +bakblu="$(tput setab 4 2>/dev/null || echo '\e[44m')" # Blue +bakpur="$(tput setab 5 2>/dev/null || echo '\e[45m')" # Purple +bakcyn="$(tput setab 6 2>/dev/null || echo '\e[46m')" # Cyan +bakwht="$(tput setab 7 2>/dev/null || echo '\e[47m')" # White -txtrst="$(tput sgr 0)" # Text Reset +# Reset +txtrst="$(tput sgr 0 2>/dev/null || echo '\e[0m')" # Text Reset