Fix #5036: quickstart: Typing Ctrl-U clears the whole of line

This commit is contained in:
Takeshi KOMIYA 2018-06-08 22:35:14 +09:00
parent ac9f973c9b
commit c15e2f3eff
3 changed files with 26 additions and 7 deletions

View File

@ -26,6 +26,7 @@ Bugs fixed
* C++, fix lookup of full template specializations with no template arguments. * C++, fix lookup of full template specializations with no template arguments.
* #4667: C++, fix assertion on missing references in global scope when using * #4667: C++, fix assertion on missing references in global scope when using
intersphinx. Thanks to Alan M. Carroll. intersphinx. Thanks to Alan M. Carroll.
* #5036: quickstart: Typing Ctrl-U clears the whole of line
Testing Testing
-------- --------

View File

@ -38,7 +38,7 @@ from six.moves.urllib.parse import quote as urlquote
from sphinx import __display_version__, package_dir from sphinx import __display_version__, package_dir
from sphinx.util import texescape from sphinx.util import texescape
from sphinx.util.console import ( # type: ignore 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.osutil import ensuredir, make_filename
from sphinx.util.template import SphinxRenderer from sphinx.util.template import SphinxRenderer
@ -82,8 +82,14 @@ PROMPT_PREFIX = '> '
# function to get input from terminal -- overridden by the test suite # function to get input from terminal -- overridden by the test suite
def term_input(prompt): def term_input(prompt):
# type: (unicode) -> unicode # type: (unicode) -> unicode
print(prompt, end='') if sys.platform == 'win32':
return input('') # 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): class ValidationError(Exception):
@ -183,7 +189,7 @@ def do_prompt(text, default=None, validator=nonempty):
prompt = prompt.encode('utf-8') prompt = prompt.encode('utf-8')
except UnicodeEncodeError: except UnicodeEncodeError:
prompt = prompt.encode('latin1') prompt = prompt.encode('latin1')
prompt = purple(prompt) prompt = colorize('purple', prompt, input_mode=True)
x = term_input(prompt).strip() x = term_input(prompt).strip()
if default and not x: if default and not x:
x = default x = default

View File

@ -87,9 +87,21 @@ def coloron():
codes.update(_orig_codes) codes.update(_orig_codes)
def colorize(name, text): def colorize(name, text, input_mode=False):
# type: (str, unicode) -> unicode # type: (str, unicode, bool) -> unicode
return codes.get(name, '') + text + codes.get('reset', '') 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): def strip_colors(s):