From 29d45a193430bc8afbda65d0cf10f692144f5f70 Mon Sep 17 00:00:00 2001 From: Fabio Erculiani Date: Thu, 29 Apr 2010 16:41:06 +0200 Subject: [PATCH] [molecule.output] disable colorized output if stdout is not a tty --- molecule/output.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/molecule/output.py b/molecule/output.py index 7215c34..bbc6b40 100644 --- a/molecule/output.py +++ b/molecule/output.py @@ -234,6 +234,19 @@ def create_color_func(color_key): for c in compat_functions_colors: setattr(sys.modules[__name__], c, create_color_func(c)) +def is_stdout_a_tty(): + """ + Return whether current stdout is a TTY. + + @return: tty? => True + @rtype: bool + """ + fn = sys.stdout.fileno() + return os.isatty(fn) + +if not is_stdout_a_tty(): + nocolor() + def print_menu(data): def orig_myfunc(x):