From 786ceeb3896cbe4d4d38b4a8fb9a939500db17e7 Mon Sep 17 00:00:00 2001 From: Gaurav Shah Date: Tue, 26 Jul 2011 15:03:37 -0700 Subject: [PATCH] Only use colored output if the terminal supports it This also removes all the tput noise we are seeing in buildbot logs. ("tput: No value for $TERM and no -T specified", "tput: unknown terminal "unknown", etc.) BUG=none TEST=manual below src/platform/scripts$ TERM=unknown; ./enter_chroot (No more tput errors) Change-Id: Ic74a0bd66d7e0cedcf7b65ec3a5f43b61b8276f9 Reviewed-on: http://gerrit.chromium.org/gerrit/4763 Tested-by: Gaurav Shah Reviewed-by: Richard Barnette --- common.sh | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/common.sh b/common.sh index 90d030f785..92c9f31e99 100644 --- a/common.sh +++ b/common.sh @@ -218,11 +218,20 @@ FACTORY_INSTALL_MASK=" /usr/share/zoneinfo " -V_REVERSE="$(tput rev)" -V_VIDOFF="$(tput sgr0)" -V_BOLD_RED="$(tput bold; tput setaf 1)" -V_BOLD_GREEN="$(tput bold; tput setaf 2)" -V_BOLD_YELLOW="$(tput bold; tput setaf 3)" +# Determine and set up variables needed for fancy color output (if supported). +V_REVERSE= +V_VIDOFF= +V_BOLD_RED= +V_BOLD_GREEN= +V_BOLD_YELLOW= + +if tput colors >/dev/null 2>&1; then + V_REVERSE="$(tput rev)" + V_VIDOFF="$(tput sgr0)" + V_BOLD_RED="$(tput bold; tput setaf 1)" + V_BOLD_GREEN="$(tput bold; tput setaf 2)" + V_BOLD_YELLOW="$(tput bold; tput setaf 3)" +fi # ----------------------------------------------------------------------------- # Functions