Skip to content

Commit

Permalink
Update termui.py
Browse files Browse the repository at this point in the history
  • Loading branch information
thejcannon authored Jan 6, 2025
1 parent 1fb06a2 commit f6e5792
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/click/termui.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,16 @@ def hidden_prompt_func(prompt: str) -> str:
def _build_prompt(
text: str,
suffix: str,
show_default: bool = False,
show_default: bool | str = False,
default: t.Any | None = None,
show_choices: bool = True,
type: ParamType | None = None,
) -> str:
prompt = text
if type is not None and show_choices and isinstance(type, Choice):
prompt += f" ({', '.join(map(str, type.choices))})"
if isinstance(show_default, str):
default = f"({show_default})"
if default is not None and show_default:
prompt = f"{prompt} [{_format_default(default)}]"
return f"{prompt}{suffix}"
Expand All @@ -88,7 +90,7 @@ def prompt(
type: ParamType | t.Any | None = None,
value_proc: t.Callable[[str], t.Any] | None = None,
prompt_suffix: str = ": ",
show_default: bool = True,
show_default: bool | str = True,
err: bool = False,
show_choices: bool = True,
) -> t.Any:
Expand All @@ -112,6 +114,8 @@ def prompt(
convert a value.
:param prompt_suffix: a suffix that should be added to the prompt.
:param show_default: shows or hides the default value in the prompt.
If this value is a string, it shows that string
in parentheses instead of the actual value.
:param err: if set to true the file defaults to ``stderr`` instead of
``stdout``, the same as with echo.
:param show_choices: Show or hide choices if the passed type is a Choice.
Expand Down

0 comments on commit f6e5792

Please sign in to comment.