Skip to content
Myr

fix backspace in prompt with readline enabled

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Saif807380 · committed by David Lord · parent b625b9f · Browse files · 3 files+10 added−6 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+10 added−6 removed

  • tests:+4 added−4 removed
  • other:+6 added−2 removed

3 files+10 added−6 removed

modified:src/click/termui.py+4 added-2 removed
125 unmodified lines
126 f = hidden_prompt_func if hide_input else visible_prompt_func127 try:128 # Write the prompt separately so that we get nice129 # coloring through colorama on Windows130 echo(text, nl=False, err=err)131 return f("")130 echo(text.rstrip(" "), nl=False, err=err)131 # Echo a space to stdout to work around an issue where132 # readline causes backspace to clear the whole line.133 return f(" ")134 except (KeyboardInterrupt, EOFError):135 # getpass doesn't print a newline if the user aborts input with ^C.136 # Allegedly this behavior is inherited from getpass(3).137 # A doc bug has been filed at https://bugs.python.org/issue24711
631 unmodified lines
modified:tests/test_utils.py+4 added-4 removed
152 unmodified lines
153154 try:155 click.prompt("Password", hide_input=True)156 except click.Abort:157 click.echo("Screw you.")157 click.echo("interrupted")158159 out, err = capsys.readouterr()160 assert out == "Password: \nScrew you.\n"160 assert out == "Password:\ninterrupted\n"161162163def _test_gen_func():164 yield "a"
89 unmodified lines
254255 emulate_input("asdlkj\n")256 click.prompt("Prompt to stderr", err=True)257 out, err = capfd.readouterr()258 assert out == ""259 assert err == "Prompt to stderr: "258 assert out == " "259 assert err == "Prompt to stderr:"260261 emulate_input("y\n")262 click.confirm("Prompt to stdin")263 out, err = capfd.readouterr()
183 unmodified lines
modified:CHANGES.rst+2 added
199 unmodified lines
200- Marked messages shown by the CLI with ``gettext()`` to allow201 applications to translate Click's built-in strings. :issue:`303`202- Writing invalid characters to ``stderr`` when using the test runner203 does not raise a ``UnicodeEncodeError``. :issue:`848`204- Fix an issue where ``readline`` would clear the entire ``prompt()``205 line instead of only the input when pressing backspace. :issue:`665`206207208Version 7.1.2209-------------
635 unmodified lines