diff --git a/questionary/prompts/confirm.py b/questionary/prompts/confirm.py index cbb5347..98eb63a 100644 --- a/questionary/prompts/confirm.py +++ b/questionary/prompts/confirm.py @@ -23,6 +23,7 @@ def confirm( style: Optional[Style] = None, auto_enter: bool = True, instruction: Optional[str] = None, + placeholder: Optional[str] = None, **kwargs: Any, ) -> Question: """A yes or no question. The user can either confirm or deny. @@ -61,6 +62,10 @@ def confirm( instruction: A message describing how to proceed through the confirmation prompt. + + placeholder: Optional placeholder text shown when no answer is selected. + The placeholder text will disappear once the user presses a key. + Returns: :class:`Question`: Question instance, ready to be prompted (using `.ask()`). """ @@ -83,6 +88,8 @@ def get_prompt_tokens(): if status["answer"] is not None: answer = YES if status["answer"] else NO tokens.append(("class:answer", answer)) + elif placeholder is not None and not status["complete"]: + tokens.append(("class:placeholder", placeholder)) return to_formatted_text(tokens) diff --git a/tests/prompts/test_confirm.py b/tests/prompts/test_confirm.py index 7345c43..0ac84fb 100644 --- a/tests/prompts/test_confirm.py +++ b/tests/prompts/test_confirm.py @@ -101,3 +101,25 @@ def test_confirm_instruction(): "confirm", message, text, instruction="Foo instruction" ) assert result is True + + +def test_confirm_placeholder(): + message = "Foo message" + text = "Y" + "\r" + placeholder = "This is a placeholder" + + result, cli = feed_cli_with_input( + "confirm", message, text, placeholder=placeholder + ) + assert result is True + + +def test_confirm_placeholder_disappears_on_input(): + message = "Foo message" + text = "n" + KeyInputs.ENTER + "\r" + placeholder = "This should disappear" + + result, cli = feed_cli_with_input( + "confirm", message, text, auto_enter=False, placeholder=placeholder + ) + assert result is False