From 68ae08a6def9132624036e0726b8200ffb21f767 Mon Sep 17 00:00:00 2001 From: Tony Tkacik Date: Thu, 29 Jun 2017 14:26:11 +0200 Subject: [PATCH] nux-runner: Do not use colors when output is not tty. Signed-off-by: Tony Tkacik --- inc/nux-base.inc.sh | 79 +++++++++++++++++++++++---------------------- 1 file changed, 41 insertions(+), 38 deletions(-) diff --git a/inc/nux-base.inc.sh b/inc/nux-base.inc.sh index 037b9c6..c5753af 100644 --- a/inc/nux-base.inc.sh +++ b/inc/nux-base.inc.sh @@ -5,46 +5,49 @@ readonly NUX_ENV_DIR=$(dirname $NUX_INC_DIR) # Color definitions -readonly nc_bold=`tput setaf 0` -readonly nc_bg_bold=`tput setab 0` -readonly nc_black=`tput setab 0` -readonly nc_bg_black=`tput setab 0` -readonly nc_cyan=`tput setaf 6` -readonly nc_bg_cyan=`tput setab 6` -readonly nc_magenta=`tput setaf 5` -readonly nc_bg_magenta=`tput setab 5` -readonly nc_red=`tput setaf 1` -readonly nc_bg_red=`tput setab 1` -readonly nc_white=`tput setaf 7` -readonly nc_bg_white=`tput setab 7` -readonly nc_green=`tput setaf 2` -readonly nc_bg_green=`tput setab 2` -readonly nc_yellow=`tput setaf 3` -readonly nc_bg_yellow=`tput setab 3` -readonly nc_blue=`tput setaf 4` -readonly nc_bg_blue=`tput setab 4` -readonly nc_end=`tput sgr0` -readonly NC_Bold=`tput bold` -readonly NC_No=`tput sgr0` # No Color -readonly NC_Black='\033[0;30m' -readonly NC_Green='\033[0;32m' -readonly NC_Red=$nc_bold$nc_red -readonly NC_BrownOrange='\033[0;33m' -readonly NC_Blue='\033[0;34m' -readonly NC_Purple='\033[0;35m' -readonly NC_Cyan='\033[0;36m' -readonly NC_LightGray='\033[0;37m' -readonly NC_DarkGray='\033[1;30m' -readonly NC_LightRed='\033[1;31m' -readonly NC_LightGreen='\033[1;32m' -readonly NC_Yellow=$nc_yellow -readonly NC_LightBlue='\033[1;34m' -readonly NC_LightPurple='\033[1;35m' -readonly NC_LightCyan='\033[1;36m' -readonly NC_White=$nc_white +if [ -t 1 ]; then + readonly nc_bold=`tput setaf 0` + readonly nc_bg_bold=`tput setab 0` + readonly nc_black=`tput setab 0` + readonly nc_bg_black=`tput setab 0` + readonly nc_cyan=`tput setaf 6` + readonly nc_bg_cyan=`tput setab 6` + readonly nc_magenta=`tput setaf 5` + readonly nc_bg_magenta=`tput setab 5` + readonly nc_red=`tput setaf 1` + readonly nc_bg_red=`tput setab 1` + readonly nc_white=`tput setaf 7` + readonly nc_bg_white=`tput setab 7` + readonly nc_green=`tput setaf 2` + readonly nc_bg_green=`tput setab 2` + readonly nc_yellow=`tput setaf 3` + readonly nc_bg_yellow=`tput setab 3` + readonly nc_blue=`tput setaf 4` + readonly nc_bg_blue=`tput setab 4` + readonly nc_end=`tput sgr0` -readonly NC_error=$NC_Red + readonly NC_Bold=`tput bold` + readonly NC_No=`tput sgr0` # No Color + readonly NC_Black='\033[0;30m' + readonly NC_Green='\033[0;32m' + readonly NC_Red=$nc_bold$nc_red + readonly NC_BrownOrange='\033[0;33m' + readonly NC_Blue='\033[0;34m' + readonly NC_Purple='\033[0;35m' + readonly NC_Cyan='\033[0;36m' + readonly NC_LightGray='\033[0;37m' + readonly NC_DarkGray='\033[1;30m' + readonly NC_LightRed='\033[1;31m' + readonly NC_LightGreen='\033[1;32m' + readonly NC_Yellow=$nc_yellow + readonly NC_LightBlue='\033[1;34m' + readonly NC_LightPurple='\033[1;35m' + readonly NC_LightCyan='\033[1;36m' + readonly NC_White=$nc_white + + readonly NC_error=$NC_Red +fi ## #Public functions: ## ## ##Logging