Skip to content

Commit

Permalink
Merge pull request #2093 from alex-ball/patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
davidism authored Oct 10, 2021
2 parents 3737511 + f31d564 commit 3dde6c5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 3dde6c5

Please sign in to comment.