Skip to content

Add placeholder parameter support to confirm prompt#486

Open
veeceey wants to merge 1 commit into
tmbo:masterfrom
veeceey:fix/issue-470-confirm-placeholder
Open

Add placeholder parameter support to confirm prompt#486
veeceey wants to merge 1 commit into
tmbo:masterfrom
veeceey:fix/issue-470-confirm-placeholder

Conversation

@veeceey

@veeceey veeceey commented Feb 8, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Added support for the placeholder parameter to the questionary.confirm() prompt
  • The placeholder text is displayed when no answer has been selected
  • The placeholder disappears once the user presses a key (y/n/Y/N), matching the behavior of other questionary prompts
  • Added comprehensive test coverage for the new functionality

Issue

Fixes #470

Test plan

  • All existing tests pass (165/165)
  • Added two new tests:
    • test_confirm_placeholder: Verifies placeholder parameter is accepted
    • test_confirm_placeholder_disappears_on_input: Verifies placeholder disappears after user input
  • Manual testing confirms the placeholder displays correctly and disappears when typing

Changes

Modified files:

  • questionary/prompts/confirm.py: Added placeholder parameter and logic to display it in the prompt tokens
  • tests/prompts/test_confirm.py: Added test coverage for placeholder functionality

Behavior:

  • Before: Placeholder parameter was ignored in confirm prompts
  • After: Placeholder text displays when no answer is selected and disappears when user types y/n

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 tmbo#470
@veeceey

veeceey commented Feb 19, 2026

Copy link
Copy Markdown
Contributor Author

Friendly ping - any chance someone could take a look at this when they get a chance? Happy to make any changes if needed.

@kiancross kiancross left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR - I've left a couple of comments.

Comment on lines +66 to +67
placeholder: Optional placeholder text shown when no answer is selected.
The placeholder text will disappear once the user presses a key.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
placeholder: Optional placeholder text shown when no answer is selected.
The placeholder text will disappear once the user presses a key.
placeholder: Optional placeholder text shown when no answer is selected.
The placeholder text will disappear once the user presses a key.

Comment on lines +106 to +125
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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests don't exercise the placeholder logic. Both only assert the y/n result, which passes regardless of whether the placeholder renders or clears.

Could you assert on what's displayed: that the class:placeholder token is present before any key is pressed, and gone once an answer is given?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

questionary.confirm with placeholder does not clear the placeholder text

2 participants