Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed click.prompt not working with readline module #1836

Merged
merged 1 commit into from
Apr 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ Unreleased
applications to translate Click's built-in strings. :issue:`303`
- Writing invalid characters to ``stderr`` when using the test runner
does not raise a ``UnicodeEncodeError``. :issue:`848`
- Fix an issue where ``readline`` would clear the entire ``prompt()``
line instead of only the input when pressing backspace. :issue:`665`


Version 7.1.2
Expand Down
6 changes: 4 additions & 2 deletions src/click/termui.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,10 @@ def prompt_func(text):
try:
# Write the prompt separately so that we get nice
# coloring through colorama on Windows
echo(text, nl=False, err=err)
return f("")
echo(text.rstrip(" "), nl=False, err=err)
# Echo a space to stdout to work around an issue where
# readline causes backspace to clear the whole line.
return f(" ")
except (KeyboardInterrupt, EOFError):
# getpass doesn't print a newline if the user aborts input with ^C.
# Allegedly this behavior is inherited from getpass(3).
Expand Down
8 changes: 4 additions & 4 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,10 @@ def f(_):
try:
click.prompt("Password", hide_input=True)
except click.Abort:
click.echo("Screw you.")
click.echo("interrupted")

out, err = capsys.readouterr()
assert out == "Password: \nScrew you.\n"
assert out == "Password:\ninterrupted\n"


def _test_gen_func():
Expand Down Expand Up @@ -255,8 +255,8 @@ def emulate_input(text):
emulate_input("asdlkj\n")
click.prompt("Prompt to stderr", err=True)
out, err = capfd.readouterr()
assert out == ""
assert err == "Prompt to stderr: "
assert out == " "
assert err == "Prompt to stderr:"

emulate_input("y\n")
click.confirm("Prompt to stdin")
Expand Down