Merge pull request #942 from dagwieers/color-capability

Check for terminal capabilities if curses is available
pull/4420/head
Michael DeHaan 2012-08-24 16:44:29 -07:00
commit 98483f5252
1 changed files with 13 additions and 1 deletions

View File

@ -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"
#