]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
test output: only use ansi codes when run in a terminal
authorThomas Otto <thomas.otto@pdv-fs.de>
Thu, 17 Oct 2019 11:26:50 +0000 (13:26 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Thu, 17 Oct 2019 18:49:24 +0000 (20:49 +0200)
test/run

index 13def5915e675a327a4f72cf66c916d9d2694c37..a85d300b3ad970f1389e256c79813fa00fdeb438 100755 (executable)
--- a/test/run
+++ b/test/run
 # this program; if not, write to the Free Software Foundation, Inc., 51
 # Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
+
+# only use ansi color codes if output is to a terminal
+if [[ -t 1 ]]; then
+    ansi_boldgreen='\033[1;32m'
+    ansi_boldred='\033[1;31m'
+    ansi_bold='\033[1m'
+    ansi_reset='\033[1;0m'
+fi
+
 green() {
-    printf "\033[1;32m$*\033[0;0m\n"
+    printf "$ansi_boldgreen$*$ansi_reset\n"
 }
 
 red() {
-    printf "\033[1;31m$*\033[0;0m\n"
+    printf "$ansi_boldred$*$ansi_reset\n"
 }
 
 bold() {
-    printf "\033[1m$*\033[0m\n"
+    printf "$ansi_bold$*$ansi_reset\n"
 }
 
 test_failed() {