diff options
author | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2018-06-08 22:35:14 +0900 |
---|---|---|
committer | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2018-06-11 14:24:17 +0900 |
commit | c15e2f3eff669f02540f66947b73639613965a08 (patch) | |
tree | 70996ddfc0a31d20b6bee37854a13bb141b07501 /sphinx/util/console.py | |
parent | ac9f973c9be70c9f253a42939a73035be1e9e6aa (diff) | |
download | sphinx-git-c15e2f3eff669f02540f66947b73639613965a08.tar.gz |
Fix #5036: quickstart: Typing Ctrl-U clears the whole of line
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): |