diff options
author | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2018-06-14 10:41:10 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-14 10:41:10 +0900 |
commit | 62b6d209dc181978f202172e7338dabfdf21e1f4 (patch) | |
tree | 5f0c61dcfa2e9bcd469d92d18130eb02b6c5f196 | |
parent | 503eb7f2fd8f385c650267a20f48b81c0d62f96a (diff) | |
parent | 3ac069ae57ca7e1eebb77762590cfc43a839337d (diff) | |
download | sphinx-git-62b6d209dc181978f202172e7338dabfdf21e1f4.tar.gz |
Merge pull request #5059 from tk0miya/5036_quickstart
Fix #5036: quickstart: Typing Ctrl-U clears the whole of line
-rw-r--r-- | CHANGES | 1 | ||||
-rw-r--r-- | sphinx/cmd/quickstart.py | 14 | ||||
-rw-r--r-- | sphinx/util/console.py | 18 |
3 files changed, 26 insertions, 7 deletions
@@ -28,6 +28,7 @@ Bugs fixed intersphinx. Thanks to Alan M. Carroll. * #5019: autodoc: crashed by Form Feed Character * #5032: autodoc: loses the first staticmethod parameter for old styled classes +* #5036: quickstart: Typing Ctrl-U clears the whole of line Testing -------- diff --git a/sphinx/cmd/quickstart.py b/sphinx/cmd/quickstart.py index 68718eeaf..8b928b478 100644 --- a/sphinx/cmd/quickstart.py +++ b/sphinx/cmd/quickstart.py @@ -38,7 +38,7 @@ from six.moves.urllib.parse import quote as urlquote from sphinx import __display_version__, package_dir from sphinx.util import texescape from sphinx.util.console import ( # type: ignore - purple, bold, red, turquoise, nocolor, color_terminal + colorize, bold, red, turquoise, nocolor, color_terminal ) from sphinx.util.osutil import ensuredir, make_filename from sphinx.util.template import SphinxRenderer @@ -82,8 +82,14 @@ PROMPT_PREFIX = '> ' # function to get input from terminal -- overridden by the test suite def term_input(prompt): # type: (unicode) -> unicode - print(prompt, end='') - return input('') + if sys.platform == 'win32': + # Important: On windows, readline is not enabled by default. In these + # environment, escape sequences have been broken. To avoid the + # problem, quickstart uses ``print()`` to show prompt. + print(prompt, end='') + return input('') + else: + return input(prompt) class ValidationError(Exception): @@ -183,7 +189,7 @@ def do_prompt(text, default=None, validator=nonempty): prompt = prompt.encode('utf-8') except UnicodeEncodeError: prompt = prompt.encode('latin1') - prompt = purple(prompt) + prompt = colorize('purple', prompt, input_mode=True) x = term_input(prompt).strip() if default and not x: x = default 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): |