Skip to content

Commit

Permalink
Check for terminal capabilities if curses is available
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
dagwieers committed Aug 24, 2012
1 parent bf92a9e commit 47f3be3
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion lib/ansible/color.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,20 @@
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"
#
Expand Down

0 comments on commit 47f3be3

Please sign in to comment.