diff --git a/django/core/management/color.py b/django/core/management/color.py index 40fd4e7fdd..337e0f2e68 100644 --- a/django/core/management/color.py +++ b/django/core/management/color.py @@ -6,10 +6,22 @@ import sys from django.utils import termcolors +def supports_color(): + """ + Returns True if the running system's terminal supports color, and False + otherwise. + """ + unsupported_platform = (sys.platform in ('win32', 'Pocket PC') + or sys.platform.startswith('java')) + # isatty is not always implemented, #6223. + is_a_tty = hasattr(sys.stdout, 'isatty') and sys.stdout.isatty() + if unsupported_platform or not is_a_tty: + return False + return True + def color_style(): """Returns a Style object with the Django color scheme.""" - if (sys.platform == 'win32' or sys.platform == 'Pocket PC' - or sys.platform.startswith('java') or not sys.stdout.isatty()): + if not supports_color(): return no_style() class dummy: pass style = dummy()