From bb2d3223f87f9bb7dd768c3a6a3c06426eda8ba2 Mon Sep 17 00:00:00 2001 From: Hubert Kario Date: Sat, 19 Sep 2015 16:16:11 +0200 Subject: [PATCH] autodetect if the colors should be used check if the terminal output doesn't go to a pipe (less, file, etc.) don't output colors by default then --- cipherscan | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/cipherscan b/cipherscan index 81406fa..4d54bea 100755 --- a/cipherscan +++ b/cipherscan @@ -197,7 +197,7 @@ DELAY=0 ALLCIPHERS="" OUTPUTFORMAT="terminal" TIMEOUT=30 -USECOLORS="True" +USECOLORS="auto" # place where to put the found intermediate CA certificates and where # trust anchors are stored SAVECRT="" @@ -250,6 +250,7 @@ Use one of the options below: --[no-]curves test ECC curves supported by server (req. OpenSSL 1.0.2) --[no-]tolerance test TLS tolerance --no-sni don't use Server Name Indication +--colors force use of colors (autodetect by default) --no-colors don't use terminal colors -v | --verbose Increase verbosity. @@ -690,7 +691,14 @@ display_results_in_terminal() { local curvesordering local different=False # Configure colors, if terminal supports them - if [[ $USECOLORS == "True" && -x /usr/bin/tput ]] && tput setaf 1 >&/dev/null; then + if [[ $USECOLORS == "auto" ]]; then + if [[ -t 1 ]]; then + USECOLORS="True" + else + USECOLORS="False" + fi + fi + if [[ $USECOLORS == "True" ]]; then c_blue="\033[0;34m" c_green="\033[0;32m" c_red="\033[0;31m" @@ -1422,6 +1430,10 @@ do TEST_TOLERANCE="False" shift 1 ;; + --colors) + USECOLORS="True" + shift 1 + ;; --no-colors) USECOLORS="False" shift 1