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).
This commit is contained in:
Dag Wieërs 2012-08-25 00:38:17 +02:00
parent bf92a9e4e0
commit 47f3be3de0

View file

@ -21,7 +21,19 @@ import sys
ANSIBLE_COLOR=True ANSIBLE_COLOR=True
if os.getenv("ANSIBLE_NOCOLOR") is not None: if os.getenv("ANSIBLE_NOCOLOR") is not None:
ANSIBLE_COLOR=False 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 ANSIBLE_COLOR=False
# --- begin "pretty" # --- begin "pretty"