From eb453c6570d20dde133e4640a547752ad24f6ede Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Sun, 29 May 2016 08:15:40 +0200 Subject: [PATCH] installer: extract color sequences definition --- tools/install.sh | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/tools/install.sh b/tools/install.sh index 187c828f..7fb6c70b 100755 --- a/tools/install.sh +++ b/tools/install.sh @@ -1,10 +1,15 @@ -main() { - # Use colors, but only if connected to a terminal, and that terminal - # supports them. +#!/bin/sh + +# Set up color sequences +setup_color() { if which tput >/dev/null 2>&1; then - ncolors=$(tput colors) + ncolors=$(tput colors) + else + ncolors=0 fi - if [ -t 1 ] && [ -n "$ncolors" ] && [ "$ncolors" -ge 8 ]; then + + # Only use colors if connected to a terminal that supports them + if [ -t 1 ] && [ $ncolors -ge 8 ]; then RED="$(tput setaf 1)" GREEN="$(tput setaf 2)" YELLOW="$(tput setaf 3)" @@ -19,6 +24,10 @@ main() { BOLD="" NORMAL="" fi +} + +main() { + setup_color # Only enable exit-on-error after the non-critical colorization stuff, # which may fail on systems lacking tput or terminfo