Skip to content
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 @@ -11,6 +11,8 @@ Unreleased
the ``Context.invoke()`` method. :issue:`3066` :issue:`3065` :pr:`3068`
- Fix conversion of ``Sentinel.UNSET`` happening too early, which caused incorrect
behavior for multiple parameters using the same name. :issue:`3071` :pr:`3079`
- Fix rendering when ``prompt`` and ``confirm`` parameter ``prompt_suffix`` is
empty. :issue:`3019` :pr:`3021`

Version 8.3.0
--------------
Expand Down
18 changes: 12 additions & 6 deletions src/click/termui.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ def prompt(
show_choices is true and text is "Group by" then the
prompt will be "Group by (day, week): ".

.. versionchanged:: 8.3.1
A space is no longer appended to the prompt.

.. versionadded:: 8.0
``confirmation_prompt`` can be a custom string.

Expand All @@ -138,10 +141,10 @@ def prompt_func(text: str) -> str:
try:
# Write the prompt separately so that we get nice
# coloring through colorama on Windows
echo(text.rstrip(" "), nl=False, err=err)
# Echo a space to stdout to work around an issue where
echo(text[:-1], nl=False, err=err)
# Echo the last character to stdout to work around an issue where
# readline causes backspace to clear the whole line.
return f(" ")
return f(text[-1:])
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 Expand Up @@ -214,6 +217,9 @@ def confirm(
:param err: if set to true the file defaults to ``stderr`` instead of
``stdout``, the same as with echo.

.. versionchanged:: 8.3.1
A space is no longer appended to the prompt.

.. versionchanged:: 8.0
Repeat until input is given if ``default`` is ``None``.

Expand All @@ -231,10 +237,10 @@ def confirm(
try:
# Write the prompt separately so that we get nice
# coloring through colorama on Windows
echo(prompt.rstrip(" "), nl=False, err=err)
# Echo a space to stdout to work around an issue where
echo(prompt[:-1], nl=False, err=err)
# Echo the last character to stdout to work around an issue where
# readline causes backspace to clear the whole line.
value = visible_prompt_func(" ").lower().strip()
value = visible_prompt_func(prompt[-1:]).lower().strip()
except (KeyboardInterrupt, EOFError):
raise Abort() from None
if value in ("y", "yes"):
Expand Down
24 changes: 24 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,24 +481,48 @@ def emulate_input(text):
assert out == "Prompt to stdin: "
assert err == ""

emulate_input("asdlkj\n")
click.prompt("Prompt to stdin with no suffix", prompt_suffix="")
out, err = capfd.readouterr()
assert out == "Prompt to stdin with no suffix"
assert err == ""

emulate_input("asdlkj\n")
click.prompt("Prompt to stderr", err=True)
out, err = capfd.readouterr()
assert out == " "
assert err == "Prompt to stderr:"

emulate_input("asdlkj\n")
click.prompt("Prompt to stderr with no suffix", prompt_suffix="", err=True)
out, err = capfd.readouterr()
assert out == "x"
assert err == "Prompt to stderr with no suffi"

emulate_input("y\n")
click.confirm("Prompt to stdin")
out, err = capfd.readouterr()
assert out == "Prompt to stdin [y/N]: "
assert err == ""

emulate_input("y\n")
click.confirm("Prompt to stdin with no suffix", prompt_suffix="")
out, err = capfd.readouterr()
assert out == "Prompt to stdin with no suffix [y/N]"
assert err == ""

emulate_input("y\n")
click.confirm("Prompt to stderr", err=True)
out, err = capfd.readouterr()
assert out == " "
assert err == "Prompt to stderr [y/N]:"

emulate_input("y\n")
click.confirm("Prompt to stderr with no suffix", prompt_suffix="", err=True)
out, err = capfd.readouterr()
assert out == "]"
assert err == "Prompt to stderr with no suffix [y/N"

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

Expand Down
Loading