Windows color console support. update for pull request #252.

This commit is contained in:
Takayuki Shimizukawa 2014-07-05 01:16:33 +09:00
parent 6fc7a1ac3c
commit 6ab7a2cbec
3 changed files with 14 additions and 6 deletions

View File

@ -39,6 +39,7 @@ New features
submodule documentation. Thanks to Wes Turner and Luc Saffre.
* #1434: Provide non-minified JS files for jquery.js and underscore.js to
clarify the source of the minified files.
* PR#252: Windows color console support. Thanks to meu31.
Bugs fixed
----------

View File

@ -49,6 +49,9 @@ requires = [
'six', 'Jinja2>=2.3', 'Pygments>=1.2', 'docutils>=0.10', 'snowballstemmer>=1.1'
]
if sys.platform == 'win32':
requires.append('colorama')
# Provide a "compile_catalog" command that also creates the translated
# JavaScript files if Babel is available.

View File

@ -13,6 +13,12 @@ import os
import sys
import re
try:
# check if colorama is installed to support color on Windows
import colorama
except ImportError:
colorama = None
_ansi_re = re.compile('\x1b\\[(\\d\\d;){0,2}\\d\\dm')
codes = {}
@ -42,6 +48,9 @@ def term_width_line(text):
return text.ljust(_tw + len(text) - len(_ansi_re.sub('', text))) + '\r'
def color_terminal():
if sys.platform == 'win32' and colorama is not None:
colorama.init()
return True
if not hasattr(sys.stdout, 'isatty'):
return False
if not sys.stdout.isatty():
@ -55,12 +64,7 @@ def color_terminal():
def nocolor():
# check if colorama is installed to support color on Windows
try:
import colorama
colorama.init()
except ImportError:
codes.clear()
codes.clear()
def coloron():
codes.update(_orig_codes)