判断终端是否支持彩色echo

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

View File

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