Skip to content
Myr

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

3 files+38 added−6 removed

modified:src/click/termui.py+12 added-6 removed
117 unmodified lines
118 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): ".121122 .. versionchanged:: 8.3.1123 A space is no longer appended to the prompt.124125 .. versionadded:: 8.0126 ``confirmation_prompt`` can be a custom string.127128 .. versionadded:: 7.0
11 unmodified lines
140 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/issue24711
64 unmodified lines
216 :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.219220 .. versionchanged:: 8.3.1221 A space is no longer appended to the prompt.222223 .. versionchanged:: 8.0224 Repeat until input is given if ``default`` is ``None``.225226 .. versionadded:: 4.0
9 unmodified lines
236 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 = True
636 unmodified lines
modified:tests/test_utils.py+24 added
480 unmodified lines
481 assert out == "Prompt to stdin: "482 assert err == ""483484 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 == ""489490 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:"495496 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"501502 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 == ""507508 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 == ""513514 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]:"519520 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"525526 monkeypatch.setattr(click.termui, "isatty", lambda x: True)527 monkeypatch.setattr(click.termui, "getchar", lambda: " ")528529 click.pause("Pause to stdout")
217 unmodified lines
modified:CHANGES.rst+2 added
9 unmodified lines
10- 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`1617Version 8.3.018--------------19
1287 unmodified lines