summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Reisner <dreisner@archlinux.org>2013-01-21 18:53:26 +0100
committerDave Reisner <dreisner@archlinux.org>2013-01-21 19:51:41 +0100
commitabb3d580e49b8b28c161a047012c7121767d3b3c (patch)
tree48dca64f8aa53f8f954d58e0d486b9c424ce9a28
parent1257d537a3ff62e2c543afb1ef4f807a003c9f2f (diff)
downloadmkinitcpio-abb3d580e49b8b28c161a047012c7121767d3b3c.tar.gz
mkinitcpio-abb3d580e49b8b28c161a047012c7121767d3b3c.tar.xz
Do more to determine the color caps of the term
823e24 wasn't really correct, since running 'tput setaf 0' effectively sanity checks the terminfo as well as checking existance. However, it does nothing to affirm that the terminal is capable of supporting colors. Moreover, *never* fall back on the hardcoded escapes as doing so implies that we've found a broken terminfo and we have no idea what the terminal is capable of doing. This reverts commit 823e2454176d4381cd3acc30481e9d84cdc298b1.
-rw-r--r--functions18
-rwxr-xr-xlsinitcpio17
-rwxr-xr-xmkinitcpio17
3 files changed, 20 insertions, 32 deletions
diff --git a/functions b/functions
index 8be43ed..2286ac1 100644
--- a/functions
+++ b/functions
@@ -668,4 +668,22 @@ run_build_hook() {
return 0
}
+try_enable_color() {
+ local colors
+
+ if ! colors=$(tput colors 2>/dev/null); then
+ warning "Failed to enable color. Check your TERM environment variable"
+ return
+ fi
+
+ if (( colors > 0 )) && tput setaf 0 &>/dev/null; then
+ _color_none=$(tput sgr0)
+ _color_bold=$(tput bold)
+ _color_blue=$_color_bold$(tput setaf 4)
+ _color_green=$_color_bold$(tput setaf 2)
+ _color_red=$_color_bold$(tput setaf 1)
+ _color_yellow=$_color_bold$(tput setaf 3)
+ fi
+}
+
# vim: set ft=sh ts=4 sw=4 et:
diff --git a/lsinitcpio b/lsinitcpio
index c4129d5..0a60399 100755
--- a/lsinitcpio
+++ b/lsinitcpio
@@ -258,22 +258,7 @@ done
_image=$1
if [[ -t 1 ]] && (( _optcolor )); then
- # prefer terminal safe colored and bold text when tput is supported
- if type -P tput >/dev/null; then
- _color_none="$(tput sgr0)"
- _color_bold="$(tput bold)"
- _color_blue="$_color_bold$(tput setaf 4)"
- _color_green="$_color_bold$(tput setaf 2)"
- _color_red="$_color_bold$(tput setaf 1)"
- _color_yellow="$_color_bold$(tput setaf 3)"
- else
- _color_none="\e[1;0m"
- _color_bold="\e[1;1m"
- _color_blue="$_color_bold\e[1;34m"
- _color_green="$_color_bold\e[1;32m"
- _color_red="$_color_bold\e[1;31m"
- _color_yellow="$_color_bold\e[1;33m"
- fi
+ try_enable_color
fi
[[ $_image ]] || die "No image specified (use -h for help)"
diff --git a/mkinitcpio b/mkinitcpio
index d5cf895..9802fd5 100755
--- a/mkinitcpio
+++ b/mkinitcpio
@@ -414,22 +414,7 @@ while :; do
done
if [[ -t 1 ]] && (( _optcolor )); then
- # prefer terminal safe colored and bold text when tput is supported
- if type -P tput >/dev/null; then
- _color_none="$(tput sgr0)"
- _color_bold="$(tput bold)"
- _color_blue="$_color_bold$(tput setaf 4)"
- _color_green="$_color_bold$(tput setaf 2)"
- _color_red="$_color_bold$(tput setaf 1)"
- _color_yellow="$_color_bold$(tput setaf 3)"
- else
- _color_none="\e[1;0m"
- _color_bold="\e[1;1m"
- _color_blue="$_color_bold\e[1;34m"
- _color_green="$_color_bold\e[1;32m"
- _color_red="$_color_bold\e[1;31m"
- _color_yellow="$_color_bold\e[1;33m"
- fi
+ try_enable_color
fi
# insist that /proc and /dev be mounted (important for chroots)