判断终端是否支持彩色echo

This commit is contained in:
Webpage
2024-07-22 17:49:49 +08:00
parent 923a8b36c2
commit b11e08bc88

View File

@@ -204,17 +204,18 @@ if [[ $Shell_LANG != "" ]]; then
fi fi
[[ $LANG = "" ]] && LANG="$(getprop "persist.sys.locale")" [[ $LANG = "" ]] && LANG="$(getprop "persist.sys.locale")"
echoRgb() { echoRgb() {
# 判斷是否支援彩色
if [ -t 1 ] && [ "$TERM" ]; then
#轉換echo顏色提高可讀性 #轉換echo顏色提高可讀性
if [[ $2 = 0 ]]; then case $2 in
echo -e "\e[38;5;197m -$1\e[0m" 0)echo -e "\e[38;5;197m -$1\e[0m";;
elif [[ $2 = 1 ]]; then 1)echo -e "\e[38;5;121m -$1\e[0m";;
echo -e "\e[38;5;121m -$1\e[0m" 2)echo -e "\e[38;5;${rgb_c}m -$1\e[0m";;
elif [[ $2 = 2 ]]; then 3)echo -e "\e[38;5;${rgb_b}m -$1\e[0m";;
echo -e "\e[38;5;${rgb_c}m -$1\e[0m" *)echo -e "\e[38;5;${rgb_a}m -$1\e[0m";;
elif [[ $2 = 3 ]]; then esac
echo -e "\e[38;5;${rgb_b}m -$1\e[0m"
else else
echo -e "\e[38;5;${rgb_a}m -$1\e[0m" echo "$1"
fi fi
} }
[ "$rgb_a" = "" ] && rgb_a=214 [ "$rgb_a" = "" ] && rgb_a=214