Skip to content

Commit

Permalink
click.confirm preserves prompt when readline is imported
Browse files Browse the repository at this point in the history
same fix as for click.prompt in 8.0.0
  • Loading branch information
alex-ball authored and davidism committed Oct 10, 2021
1 parent 3737511 commit f31d564
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Expand Up @@ -7,6 +7,8 @@ Unreleased

- Fix issue with ``Path(resolve_path=True)`` type creating invalid
paths. :issue:`2088`
- Importing ``readline`` does not cause the ``confirm()`` prompt to
disappear when pressing backspace. :issue:`2092`


Version 8.0.2
Expand Down
6 changes: 4 additions & 2 deletions src/click/termui.py
Expand Up @@ -231,8 +231,10 @@ def confirm(
try:
# Write the prompt separately so that we get nice
# coloring through colorama on Windows
echo(prompt, nl=False, err=err)
value = visible_prompt_func("").lower().strip()
echo(prompt.rstrip(" "), nl=False, err=err)
# Echo a space to stdout to work around an issue where
# readline causes backspace to clear the whole line.
value = visible_prompt_func(" ").lower().strip()
except (KeyboardInterrupt, EOFError):
raise Abort() from None
if value in ("y", "yes"):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_utils.py
Expand Up @@ -275,8 +275,8 @@ def emulate_input(text):
emulate_input("y\n")
click.confirm("Prompt to stderr", err=True)
out, err = capfd.readouterr()
assert out == ""
assert err == "Prompt to stderr [y/N]: "
assert out == " "
assert err == "Prompt to stderr [y/N]:"

monkeypatch.setattr(click.termui, "isatty", lambda x: True)
monkeypatch.setattr(click.termui, "getchar", lambda: " ")
Expand Down

0 comments on commit f31d564

Please sign in to comment.