From 3a00b37bc2ec20ad12baadfe62e1a244fbe681c0 Mon Sep 17 00:00:00 2001 From: Yousong Zhou Date: Fri, 30 Jan 2015 21:13:01 +0800 Subject: [PATCH] testenv: improve color output a bit. * testenv/misc/colour_terminal.py: Only print color codes when stdout isatty(). --- testenv/misc/colour_terminal.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/testenv/misc/colour_terminal.py b/testenv/misc/colour_terminal.py index b0849c1f..ca7a57cc 100644 --- a/testenv/misc/colour_terminal.py +++ b/testenv/misc/colour_terminal.py @@ -1,6 +1,7 @@ from functools import partial import platform from os import getenv +import sys """ This module allows printing coloured output to the terminal when running a Wget Test under certain conditions. @@ -25,11 +26,11 @@ T_COLORS = { 'ENDC' : '\033[0m' } -system = True if platform.system() == 'Linux' else False +system = True if platform.system() in ( 'Linux', 'Darwin' ) else False check = False if getenv("MAKE_CHECK") == 'True' else True def printer (color, string): - if system and check: + if sys.stdout.isatty() and system and check: print (T_COLORS.get (color) + string + T_COLORS.get ('ENDC')) else: print (string)