Merge pull request #93 from Webpage-gh/master

判斷終端是否支援彩色echo
This commit is contained in:
YAWAsau
2024-07-26 14:15:06 +08:00
committed by GitHub

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