diff options
Diffstat (limited to 'sphinx/util/console.py')
-rw-r--r-- | sphinx/util/console.py | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/sphinx/util/console.py b/sphinx/util/console.py index 7663feb1e..d62169adf 100644 --- a/sphinx/util/console.py +++ b/sphinx/util/console.py @@ -87,9 +87,21 @@ def coloron(): codes.update(_orig_codes) -def colorize(name, text): - # type: (str, unicode) -> unicode - return codes.get(name, '') + text + codes.get('reset', '') +def colorize(name, text, input_mode=False): + # type: (str, unicode, bool) -> unicode + def escseq(name): + # Wrap escape sequence with ``\1`` and ``\2`` to let readline know + # it is non-printable characters + # ref: https://tiswww.case.edu/php/chet/readline/readline.html + # + # Note: This hack does not work well in Windows (see #5059) + escape = codes.get(name, '') + if input_mode and escape and sys.platform != 'win32': + return '\1' + escape + '\2' + else: + return escape + + return escseq(name) + text + escseq('reset') def strip_colors(s): |