From ab2eec854d59a46f1a291bf318e996959fb57172 Mon Sep 17 00:00:00 2001 From: derwinlu Date: Tue, 20 Oct 2015 11:13:02 +0200 Subject: [PATCH] Redo ANSI support detection When using nose to directly run the test suite it 'steals' stdout per default. This causes the old implementation of ANSI detection to error as stdout does not have a fileno function anymore. --- pelican/log.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/pelican/log.py b/pelican/log.py index ddeeb6d0..d99cad88 100644 --- a/pelican/log.py +++ b/pelican/log.py @@ -172,8 +172,26 @@ class LimitLogger(SafeLogger): logging.setLoggerClass(LimitLogger) +def supports_color(): + """ + Returns True if the running system's terminal supports color, + and False otherwise. + + from django.core.management.color + """ + plat = sys.platform + supported_platform = plat != 'Pocket PC' and \ + (plat != 'win32' or 'ANSICON' in os.environ) + + # isatty is not always implemented, #6223. + is_a_tty = hasattr(sys.stdout, 'isatty') and sys.stdout.isatty() + if not supported_platform or not is_a_tty: + return False + return True + + def get_formatter(): - if os.isatty(sys.stdout.fileno()) and not sys.platform.startswith('win'): + if supports_color(): return ANSIFormatter() else: return TextFormatter()