From b11e08bc88e6d07ff061dc902537021b63554e21 Mon Sep 17 00:00:00 2001 From: Webpage <70434775+Webpage-gh@users.noreply.github.com> Date: Mon, 22 Jul 2024 17:49:49 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A4=E6=96=AD=E7=BB=88=E7=AB=AF=E6=98=AF?= =?UTF-8?q?=E5=90=A6=E6=94=AF=E6=8C=81=E5=BD=A9=E8=89=B2echo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tools/tools.sh | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/tools/tools.sh b/tools/tools.sh index cf2d546..32fc15e 100644 --- a/tools/tools.sh +++ b/tools/tools.sh @@ -204,18 +204,19 @@ if [[ $Shell_LANG != "" ]]; then fi [[ $LANG = "" ]] && LANG="$(getprop "persist.sys.locale")" echoRgb() { - #轉換echo顏色提高可讀性 - if [[ $2 = 0 ]]; then - echo -e "\e[38;5;197m -$1\e[0m" - elif [[ $2 = 1 ]]; then - echo -e "\e[38;5;121m -$1\e[0m" - elif [[ $2 = 2 ]]; then - echo -e "\e[38;5;${rgb_c}m -$1\e[0m" - elif [[ $2 = 3 ]]; then - echo -e "\e[38;5;${rgb_b}m -$1\e[0m" - else - echo -e "\e[38;5;${rgb_a}m -$1\e[0m" - fi + # 判斷是否支援彩色 + if [ -t 1 ] && [ "$TERM" ]; then + #轉換echo顏色提高可讀性 + case $2 in + 0)echo -e "\e[38;5;197m -$1\e[0m";; + 1)echo -e "\e[38;5;121m -$1\e[0m";; + 2)echo -e "\e[38;5;${rgb_c}m -$1\e[0m";; + 3)echo -e "\e[38;5;${rgb_b}m -$1\e[0m";; + *)echo -e "\e[38;5;${rgb_a}m -$1\e[0m";; + esac + else + echo "$1" + fi } [ "$rgb_a" = "" ] && rgb_a=214 if [ "$(whoami)" != root ]; then