Skip to content

Commit

Permalink
Fixed #13476 -- Added support for color in console output under Windows.
Browse files Browse the repository at this point in the history
Detect and use the services of the ANSICON third-party tool if it's
available.
  • Loading branch information
ramiro committed Dec 3, 2013
1 parent c75dd66 commit 12615da
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
6 changes: 4 additions & 2 deletions django/core/management/color.py
Expand Up @@ -13,10 +13,12 @@ def supports_color():
Returns True if the running system's terminal supports color, and False Returns True if the running system's terminal supports color, and False
otherwise. otherwise.
""" """
unsupported_platform = (sys.platform in ('win32', 'Pocket PC')) plat = sys.platform
supported_platform = plat != 'Pocket PC' and (plat != 'win32' or
'ANSICON' in os.environ)
# isatty is not always implemented, #6223. # isatty is not always implemented, #6223.
is_a_tty = hasattr(sys.stdout, 'isatty') and sys.stdout.isatty() is_a_tty = hasattr(sys.stdout, 'isatty') and sys.stdout.isatty()
if unsupported_platform or not is_a_tty: if not supported_platform or not is_a_tty:
return False return False
return True return True


Expand Down
13 changes: 13 additions & 0 deletions docs/ref/django-admin.txt
Expand Up @@ -1552,6 +1552,11 @@ color-coded output if your terminal supports ANSI-colored output. It
won't use the color codes if you're piping the command's output to won't use the color codes if you're piping the command's output to
another program. another program.


Under Windows, the native console doesn't support ANSI escape sequences so by
default there is no color output. But you can install the `ANSICON`_
third-party tool, the Django commands will detect its presence and will make
use of its services to color output just like on Unix-based platforms.

The colors used for syntax highlighting can be customized. Django The colors used for syntax highlighting can be customized. Django
ships with three color palettes: ships with three color palettes:


Expand Down Expand Up @@ -1636,6 +1641,14 @@ would specify the use of all the colors in the light color palette,
*except* for the colors for errors and notices which would be *except* for the colors for errors and notices which would be
overridden as specified. overridden as specified.


.. versionadded:: 1.7

Support for color-coded output from ``django-admin.py`` / ``manage.py``
utilities on Windows by relying on the ANSICON application was added in Django
1.7.

.. _ANSICON: http://adoxa.hostmyway.net/ansicon/

Bash completion Bash completion
--------------- ---------------


Expand Down
3 changes: 3 additions & 0 deletions docs/releases/1.7.txt
Expand Up @@ -415,6 +415,9 @@ Management Commands
* All HTTP requests are logged to the console, including requests for static * All HTTP requests are logged to the console, including requests for static
files or ``favicon.ico`` that used to be filtered out. files or ``favicon.ico`` that used to be filtered out.


* Management commands can now produce syntax colored output under Windows if
the ANSICON third-party tool is installed and active.

Models Models
^^^^^^ ^^^^^^


Expand Down

0 comments on commit 12615da

Please sign in to comment.