Fix rendering when `prompt_suffix` is empty (#3021)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Rowlando13 · committed by GitHub · parents 5f86603, 27de74a · Browse files · 3 files·+38 added−6 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+38 added−6 removed
- tests:+24 added−0 removed
- other:+14 added−6 removed
Provenance
- Commit
8533c96- Tree
ce0fdeb- Author
Rowlando13 <67291205+Rowlando13@users.noreply.github.com>- Committer
GitHub <noreply@github.com>- Parent 1
5f86603- Parent 2
27de74a
3 files changed+38 added−6 removed
modified:src/click/termui.py+12 added-6 removed
117 unmodified lines118 For example if type is a Choice of either day or week,119 show_choices is true and text is "Group by" then the120 prompt will be "Group by (day, week): ".121 122+ .. versionchanged:: 8.3.1123+ A space is no longer appended to the prompt.124+125 .. versionadded:: 8.0126 ``confirmation_prompt`` can be a custom string.127 128 .. versionadded:: 7.011 unmodified lines140 f = hidden_prompt_func if hide_input else visible_prompt_func141 try:142 # Write the prompt separately so that we get nice143 # coloring through colorama on Windows141- echo(text.rstrip(" "), nl=False, err=err)142- # Echo a space to stdout to work around an issue where144+ echo(text[:-1], nl=False, err=err)145+ # Echo the last character to stdout to work around an issue where146 # readline causes backspace to clear the whole line.144- return f(" ")147+ return f(text[-1:])148 except (KeyboardInterrupt, EOFError):149 # getpass doesn't print a newline if the user aborts input with ^C.150 # Allegedly this behavior is inherited from getpass(3).151 # A doc bug has been filed at https://bugs.python.org/issue2471164 unmodified lines216 :param show_default: shows or hides the default value in the prompt.217 :param err: if set to true the file defaults to ``stderr`` instead of218 ``stdout``, the same as with echo.219 220+ .. versionchanged:: 8.3.1221+ A space is no longer appended to the prompt.222+223 .. versionchanged:: 8.0224 Repeat until input is given if ``default`` is ``None``.225 226 .. versionadded:: 4.09 unmodified lines236 while True:237 try:238 # Write the prompt separately so that we get nice239 # coloring through colorama on Windows234- echo(prompt.rstrip(" "), nl=False, err=err)235- # Echo a space to stdout to work around an issue where240+ echo(prompt[:-1], nl=False, err=err)241+ # Echo the last character to stdout to work around an issue where242 # readline causes backspace to clear the whole line.237- value = visible_prompt_func(" ").lower().strip()243+ value = visible_prompt_func(prompt[-1:]).lower().strip()244 except (KeyboardInterrupt, EOFError):245 raise Abort() from None246 if value in ("y", "yes"):247 rv = True636 unmodified linesmodified:tests/test_utils.py+24 added
480 unmodified lines481 assert out == "Prompt to stdin: "482 assert err == ""483 484 emulate_input("asdlkj\n")485+ click.prompt("Prompt to stdin with no suffix", prompt_suffix="")486+ out, err = capfd.readouterr()487+ assert out == "Prompt to stdin with no suffix"488+ assert err == ""489+490+ emulate_input("asdlkj\n")491 click.prompt("Prompt to stderr", err=True)492 out, err = capfd.readouterr()493 assert out == " "494 assert err == "Prompt to stderr:"495 496+ emulate_input("asdlkj\n")497+ click.prompt("Prompt to stderr with no suffix", prompt_suffix="", err=True)498+ out, err = capfd.readouterr()499+ assert out == "x"500+ assert err == "Prompt to stderr with no suffi"501+502 emulate_input("y\n")503 click.confirm("Prompt to stdin")504 out, err = capfd.readouterr()505 assert out == "Prompt to stdin [y/N]: "506 assert err == ""507 508 emulate_input("y\n")509+ click.confirm("Prompt to stdin with no suffix", prompt_suffix="")510+ out, err = capfd.readouterr()511+ assert out == "Prompt to stdin with no suffix [y/N]"512+ assert err == ""513+514+ emulate_input("y\n")515 click.confirm("Prompt to stderr", err=True)516 out, err = capfd.readouterr()517 assert out == " "518 assert err == "Prompt to stderr [y/N]:"519 520+ emulate_input("y\n")521+ click.confirm("Prompt to stderr with no suffix", prompt_suffix="", err=True)522+ out, err = capfd.readouterr()523+ assert out == "]"524+ assert err == "Prompt to stderr with no suffix [y/N"525+526 monkeypatch.setattr(click.termui, "isatty", lambda x: True)527 monkeypatch.setattr(click.termui, "getchar", lambda: " ")528 529 click.pause("Pause to stdout")217 unmodified linesmodified:CHANGES.rst+2 added
9 unmodified lines10 - Replace ``Sentinel.UNSET`` default values by ``None`` as they're passed through11 the ``Context.invoke()`` method. :issue:`3066` :issue:`3065` :pr:`3068`12 - Fix conversion of ``Sentinel.UNSET`` happening too early, which caused incorrect13 behavior for multiple parameters using the same name. :issue:`3071` :pr:`3079`14+- Fix rendering when ``prompt`` and ``confirm`` parameter ``prompt_suffix`` is15+ empty. :issue:`3019` :pr:`3021`16 17 Version 8.3.018 --------------19 1287 unmodified lines