Skip to content

Commit

Permalink
add terminal check (to print color); also usage of terinfo tput OR co…
Browse files Browse the repository at this point in the history
…lor codes
  • Loading branch information
Anton-Latukha committed Sep 12, 2017
1 parent f10b1c8 commit 942dbe8
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions scripts/install-nix-from-closure.sh
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,25 @@ readonly appname="$0"
### CLI control constants
###############################
{
# tput is not present on some systems (Alpine Linux), this trick with printf allows to store, not 'codes' - literal symbols
readonly red=$(printf '\033[1;31m')
readonly green=$(printf '\033[1;32m')
readonly yellow=$(printf '\033[1;33m')
readonly blue=$(printf '\033[1;34m')
readonly bold=$(printf '\033[1m')
readonly reset=$(printf '\033[0;m') # Reset to default output
if test -t ; then # File descriptor is associated with a terminal - output colors
if tput colors; then
# use tput and terminfo DB
readonly red=$(tput setaf 1)
readonly green=$(tput setaf 2)
readonly yellow=$(tput setaf 3)
readonly blue=$(tput setaf 4)
readonly bold=$(tput smso)
readonly reset=$(tput sgr0) # Reset to default output
else
# tput is not present on some systems (Alpine Linux), this trick with printf allows to store, not 'codes' - literal symbols
readonly red=$(printf '\033[1;31m')
readonly green=$(printf '\033[1;32m')
readonly yellow=$(printf '\033[1;33m')
readonly blue=$(printf '\033[1;34m')
readonly bold=$(printf '\033[1m')
readonly reset=$(printf '\033[0;m') # Reset to default output
fi
fi
}
###############################
### CLI output functions
Expand Down

0 comments on commit 942dbe8

Please sign in to comment.