Properly handle terminals which do not have 256 colors.

This commit is contained in:
2026-07-16 16:52:16 -07:00
parent 1ea50e600e
commit 8041037eda
+27 -1
View File
@@ -9,6 +9,8 @@ export PATH="$PATH:~/bin-shared:~/.bin-shared"
# PS1 Colors #
colors=`tput colors`
if (( colors >= 256 )); then
export PURPLE="`tput setaf 55`"
export ORANGE="`tput setaf 208`"
export GREEN="`tput setaf 34`"
@@ -18,6 +20,28 @@ export SCARLET="`tput setaf 160`"
export YELLOW="`tput setaf 226`"
export GRAY="`tput setaf 243`"
elif (( colors == 16 )); then
export PURPLE="`tput setaf 13`"
export ORANGE="`tput setaf 11`"
export GREEN="`tput setaf 02`"
export RED="`tput setaf 09`"
export SCARLET="`tput setaf 01`"
export YELLOW="`tput setaf 11`"
export GRAY="`tput setaf 08`"
else
export PURPLE="`tput setaf 05`"
export ORANGE="`tput setaf 03`"
export GREEN="`tput setaf 02`"
export RED="`tput setaf 05`"
export SCARLET="`tput setaf 01`"
export YELLOW="`tput setaf 03`"
export GRAY="`tput setaf 07`"
fi
export RESET="`tput sgr0`"
export BOLD="`tput bold`"
@@ -862,8 +886,10 @@ function git-check {
# TBD: Move this to a different section?
function check-colors {
min=0
max=255
max=256
unset i
echo "Current terminal supports '`tput colors`' colors."
echo "Displaying examples..."
for (( i = min; i <= max; i++ )); do
tput setaf $i
printf "%03d" "$i"