From 47f3be3de07b1c37679ef0709e190034b59b1d69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dag=20Wie=C3=ABrs?= Date: Sat, 25 Aug 2012 00:38:17 +0200 Subject: [PATCH] Check for terminal capabilities if curses is available Normally curses is part of the standard library, but this was not always the case in the past. The ANSIBLE_COLOR environment variable and the tty-check have priority over the curses method (as they are both faster than the curses test). --- lib/ansible/color.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/ansible/color.py b/lib/ansible/color.py index c559aa1b0fe..956b33160e7 100644 --- a/lib/ansible/color.py +++ b/lib/ansible/color.py @@ -21,8 +21,20 @@ import sys ANSIBLE_COLOR=True if os.getenv("ANSIBLE_NOCOLOR") is not None: ANSIBLE_COLOR=False -if not sys.stdout.isatty(): +elif not sys.stdout.isatty(): ANSIBLE_COLOR=False +else: + try: + import curses + curses.setupterm() + if curses.tigetnum('colors') < 0: + ANSIBLE_COLOR=False + except ImportError: + # curses library was not found + pass + except curses.error: + # curses returns an error (e.g. could not find terminal) + ANSIBLE_COLOR=False # --- begin "pretty" #