Skip to content

Commit

Permalink
feat(installer): graceful fallback to monochromic output when tput
Browse files Browse the repository at this point in the history
…is unavailable (#372)

* feat(installer): gracefully monochromatic output when `tput` is unavailable

The `tput` command allows easier ANSI output using named values in rather than control characters.

While we could just use control characters and maintain colored output in the absence of `tput`, it's
probably also reasonable to gracefully fall back to monochromatic output.

Co-authored-by: Avery Harnish <[email protected]>
  • Loading branch information
abernix and EverlastingBugstopper authored Mar 26, 2021
1 parent 8c00074 commit 62f7bb7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
11 changes: 5 additions & 6 deletions installers/binstall/scripts/nix/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ download_binary_and_run_installer() {
need_cmd tar
need_cmd which
need_cmd dirname
need_cmd tput

# if $VERSION isn't provided or has 0 length, use version from Rover cargo.toml
# ${VERSION:-} checks if version exists, and if doesn't uses the default
Expand Down Expand Up @@ -143,14 +142,14 @@ get_architecture() {


say() {
local green=`tput setaf 2`
local reset=`tput sgr0`
local green=`tput setaf 2 2>/dev/null || echo ''`
local reset=`tput sgr0 2>/dev/null || echo ''`
echo "$1"
}

err() {
local red=`tput setaf 1`
local reset=`tput sgr0`
local red=`tput setaf 1 2>/dev/null || echo ''`
local reset=`tput sgr0 2>/dev/null || echo ''`
say "${red}ERROR${reset}: $1" >&2
exit 1
}
Expand Down Expand Up @@ -209,4 +208,4 @@ downloader() {
fi
}

download_binary_and_run_installer "$@" || exit 1
download_binary_and_run_installer "$@" || exit 1
12 changes: 5 additions & 7 deletions installers/binstall/scripts/nix/local-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ copy_binary_and_run_installer() {
need_cmd which
need_cmd dirname
need_cmd cargo
need_cmd tput

say "building rover"
ensure cargo build --workspace
Expand Down Expand Up @@ -101,16 +100,15 @@ get_architecture() {
RETVAL="$_arch"
}


say() {
local green=`tput setaf 2`
local reset=`tput sgr0`
local green=`tput setaf 2 2>/dev/null || echo ''`
local reset=`tput sgr0 2>/dev/null || echo ''`
echo " ${green}INFO${reset} sh::wrapper: $1"
}

err() {
local red=`tput setaf 1`
local reset=`tput sgr0`
local red=`tput setaf 1 2>/dev/null || echo ''`
local reset=`tput sgr0 2>/dev/null || echo ''`
say " ${red}ERROR${reset} sh::wrapper: $1" >&2
exit 1
}
Expand Down Expand Up @@ -149,4 +147,4 @@ ignore() {
"$@"
}

copy_binary_and_run_installer "$@" || exit 1
copy_binary_and_run_installer "$@" || exit 1

0 comments on commit 62f7bb7

Please sign in to comment.