forked from github/pelican
Redo ANSI support detection
When using nose to directly run the test suite it 'steals' stdout per default. This causes the old implementation of ANSI detection to error as stdout does not have a fileno function anymore.
This commit is contained in:
parent
22ec94ee56
commit
ab2eec854d
1 changed files with 19 additions and 1 deletions
|
|
@ -172,8 +172,26 @@ class LimitLogger(SafeLogger):
|
|||
logging.setLoggerClass(LimitLogger)
|
||||
|
||||
|
||||
def supports_color():
|
||||
"""
|
||||
Returns True if the running system's terminal supports color,
|
||||
and False otherwise.
|
||||
|
||||
from django.core.management.color
|
||||
"""
|
||||
plat = sys.platform
|
||||
supported_platform = plat != 'Pocket PC' and \
|
||||
(plat != 'win32' or 'ANSICON' in os.environ)
|
||||
|
||||
# isatty is not always implemented, #6223.
|
||||
is_a_tty = hasattr(sys.stdout, 'isatty') and sys.stdout.isatty()
|
||||
if not supported_platform or not is_a_tty:
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def get_formatter():
|
||||
if os.isatty(sys.stdout.fileno()) and not sys.platform.startswith('win'):
|
||||
if supports_color():
|
||||
return ANSIFormatter()
|
||||
else:
|
||||
return TextFormatter()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue