This patch improve coloring in light and transparent term.
It uses tput if available
\033 are remplaced by \e
Signed-off-by: Sebastien Luttringer
---
functions | 49 +++++++++++++++++++++++++++++--------------------
rc.sysinit | 4 ++--
2 files changed, 31 insertions(+), 22 deletions(-)
diff --git a/functions b/functions
index fd0928e..500ec7c 100644
--- a/functions
+++ b/functions
@@ -49,28 +49,37 @@ else
export LANG=C
fi
-# colors:
-if [[ $USECOLOR = YES || $USECOLOR = yes ]]; then
- C_MAIN="\033[1;37;40m" # main text
-
- C_OTHER="\033[1;34;40m" # prefix & brackets
- C_SEPARATOR="\033[1;30;40m" # separator
-
- C_BUSY="\033[0;36;40m" # busy
- C_FAIL="\033[1;31;40m" # failed
- C_DONE="\033[1;37;40m" # completed
- C_BKGD="\033[1;35;40m" # backgrounded
-
- C_H1="\033[1;37;40m" # highlight text 1
- C_H2="\033[1;36;40m" # highlight text 2
-
- C_CLEAR="\033[1;0m"
+# set colors
+if [[ $USECOLOR =~ yes|YES ]]; then
+ if /bin/tput setaf 0 &>/dev/null; then
+ C_CLEAR="$(tput sgr0)" # clear text
+ C_MAIN="${C_CLEAR}$(/bin/tput bold)" # main text
+ C_OTHER="${C_MAIN}$(/bin/tput setaf 4)" # prefix & brackets
+ C_SEPARATOR="${C_MAIN}$(/bin/tput setaf 0)" # separator
+ C_BUSY="${C_CLEAR}$(/bin/tput setaf 6)" # busy
+ C_FAIL="${C_MAIN}$(/bin/tput setaf 1)" # failed
+ C_DONE="${C_MAIN}" # completed
+ C_BKGD="${C_MAIN}$(/bin/tput setaf 5)" # backgrounded
+ C_H1="${C_MAIN}" # highlight text 1
+ C_H2="${C_MAIN}$(/bin/tput setaf 6)" # highlight text 2
+ else
+ C_CLEAR="\e[m" # clear text
+ C_MAIN="\e[;1m" # main text
+ C_OTHER="\e[1;34m" # prefix & brackets
+ C_SEPARATOR="\e[1;30m" # separator
+ C_BUSY="\e[;36m" # busy
+ C_FAIL="\e[1;31m" # failed
+ C_DONE="${C_MAIN}" # completed
+ C_BKGD="\e[1;35m" # backgrounded
+ C_H1="${$C_MAIN}" # highlight text 1
+ C_H2="\e[1;36m" # highlight text 2
+ fi
fi
if [[ -t 1 ]]; then
- SAVE_POSITION="\033[s"
- RESTORE_POSITION="\033[u"
- DEL_TEXT="\033[$(($STAT_COL+4))G"
+ SAVE_POSITION="\e[s"
+ RESTORE_POSITION="\e[u"
+ DEL_TEXT="\e[$(($STAT_COL+4))G"
else
SAVE_POSITION=""
RESTORE_POSITION=""
@@ -360,7 +369,7 @@ set_consolefont() {
stat_fail
elif [[ $CONSOLEMAP ]]; then
cat <<"EOF" >>/etc/profile.d/locale.sh
-if [ "$CONSOLE" = "" -a "$TERM" = "linux" -a -t 1 ]; then printf "\033(K"; fi
+if [ "$CONSOLE" = "" -a "$TERM" = "linux" -a -t 1 ]; then printf "\e(K"; fi
EOF
stat_done
else
diff --git a/rc.sysinit b/rc.sysinit
index dc4be58..7b2cdfe 100755
--- a/rc.sysinit
+++ b/rc.sysinit
@@ -352,7 +352,7 @@ if [[ ${LOCALE,,} =~ utf ]]; then
# but also when user has set vt.default_utf8=0 but LOCALE is *.UTF-8.
for i in /dev/tty[0-9]*; do
/usr/bin/kbd_mode -u < ${i}
- printf "\033%%G" > ${i}
+ printf "\e%%G" > ${i}
done
echo 1 > /sys/module/vt/parameters/default_utf8
stat_done
@@ -362,7 +362,7 @@ else
# make non-UTF-8 consoles work on 2.6.24 and newer kernels
for i in /dev/tty[0-9]*; do
/usr/bin/kbd_mode -a < ${i}
- printf "\033%%@" > ${i}
+ printf "\e%%@" > ${i}
done
echo 0 > /sys/module/vt/parameters/default_utf8
stat_done
--
Sebastien "Seblu" Luttringer