From 5cfef63658659d9ead0dd00ebeb5f78d7c2ff24e Mon Sep 17 00:00:00 2001 From: Varun Chawla Date: Sat, 7 Feb 2026 23:31:01 -0800 Subject: [PATCH] Add placeholder parameter support to confirm prompt The confirm prompt now supports an optional placeholder parameter that displays grayed-out text when no answer has been selected. The placeholder text disappears once the user presses a key (y/n/Y/N), matching the behavior of other prompts. This fix ensures consistency across all questionary prompt types. Fixes #470 --- questionary/prompts/confirm.py | 7 +++++++ tests/prompts/test_confirm.py | 22 ++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/questionary/prompts/confirm.py b/questionary/prompts/confirm.py index cbb5347e..98eb63a7 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 7345c431..0ac84fb8 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