summaryrefslogtreecommitdiff
path: root/sphinx/util/console.py
diff options
context:
space:
mode:
Diffstat (limited to 'sphinx/util/console.py')
-rw-r--r--sphinx/util/console.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/sphinx/util/console.py b/sphinx/util/console.py
index 24a22d75..fa7a4a9f 100644
--- a/sphinx/util/console.py
+++ b/sphinx/util/console.py
@@ -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,6 +64,8 @@ def color_terminal():
def nocolor():
+ if sys.platform == 'win32' and colorama is not None:
+ colorama.deinit()
codes.clear()
def coloron():