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:
parent
bf92a9e4e0
commit
47f3be3de0
1 changed files with 13 additions and 1 deletions
|
@ -21,7 +21,19 @@ 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"
|
||||
|
|
Loading…
Reference in a new issue