summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Ball <alex-ball@users.noreply.github.com>2021-10-10 16:42:07 +0100
committerDavid Lord <davidism@gmail.com>2021-10-10 10:45:48 -0700
commitf31d564ff26532151b6e45f2be163ceea247a440 (patch)
treef10ab10a044eb8b8024ee151119d8656982e5285
parent3737511d399d3910ce65450358f3bde065acf8f1 (diff)
downloadclick-f31d564ff26532151b6e45f2be163ceea247a440.tar.gz
click.confirm preserves prompt when readline is imported
same fix as for click.prompt in 8.0.0
-rw-r--r--CHANGES.rst2
-rw-r--r--src/click/termui.py6
-rw-r--r--tests/test_utils.py4
3 files changed, 8 insertions, 4 deletions
diff --git a/CHANGES.rst b/CHANGES.rst
index c52c160..e6e8e9b 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -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
diff --git a/src/click/termui.py b/src/click/termui.py
index a023f42..cf8d5f1 100644
--- a/src/click/termui.py
+++ b/src/click/termui.py
@@ -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"):
diff --git a/tests/test_utils.py b/tests/test_utils.py
index d21b246..271177d 100644
--- a/tests/test_utils.py
+++ b/tests/test_utils.py
@@ -275,8 +275,8 @@ def test_echo_writing_to_standard_error(capfd, monkeypatch):
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: " ")