CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-inquirerpy

Python port of Inquirer.js providing interactive command-line user interfaces with extensive customization options.

Pending
Overview
Eval results
Files

confirmation.mddocs/

Confirmation Prompts

Yes/no confirmation prompts with single keypress operation and customizable confirmation letters for quick user decisions.

Capabilities

Confirm Prompt

Boolean confirmation prompt that accepts single keypress input for quick yes/no decisions.

def confirm(
    message: InquirerPyMessage,
    default: InquirerPyDefault = False,
    qmark: str = "?",
    amark: str = "?",
    instruction: str = "",
    long_instruction: str = "",
    transformer: Optional[Callable[[bool], Any]] = None,
    filter: Optional[Callable[[bool], Any]] = None,
    keybindings: Optional[InquirerPyKeybindings] = None,
    wrap_lines: bool = True,
    confirm_letter: str = "y",
    reject_letter: str = "n",
    mandatory: bool = True,
    mandatory_message: str = "Mandatory prompt",
    style: Optional[InquirerPyStyle] = None,
    vi_mode: bool = False,
    raise_keyboard_interrupt: bool = True,
    session_result: Optional[InquirerPySessionResult] = None,
    **kwargs
) -> bool

Parameters:

  • message: The confirmation question text
  • default: Default boolean value (True/False)
  • confirm_letter: Single character for "yes" (default: "y")
  • reject_letter: Single character for "no" (default: "n")
  • transformer: Function to transform the boolean result for display
  • filter: Function to transform the actual returned value
  • mandatory: Whether the prompt requires an answer
  • vi_mode: Note - VI mode is disabled for confirm prompts

Returns: Boolean value based on user input

Usage Examples:

Basic confirmation:

from InquirerPy import inquirer

# Simple yes/no confirmation
proceed = inquirer.confirm(message="Do you want to continue?").execute()
if proceed:
    print("Continuing...")
else:
    print("Cancelled.")

With custom default and letters:

# Default to True with custom letters
save_changes = inquirer.confirm(
    message="Save changes before exit?",
    default=True,
    confirm_letter="s",
    reject_letter="d",
    instruction="(s)ave or (d)iscard"
).execute()

With transformation:

# Transform boolean to custom strings
result = inquirer.confirm(
    message="Enable debug mode?",
    default=False,
    transformer=lambda result: "Enabled" if result else "Disabled"
).execute()
print(f"Debug mode: {result}")

Class-based Usage

Direct class instantiation for advanced customization:

from InquirerPy.prompts import ConfirmPrompt

# ConfirmPrompt class
confirm_prompt = ConfirmPrompt(
    message="Delete all files?",
    default=False,
    confirm_letter="d",
    reject_letter="k",
    instruction="(d)elete or (k)eep",
    transformer=lambda result: "DELETED" if result else "KEPT"
)

confirmed = confirm_prompt.execute()
print(f"Action: {confirmed}")

Keyboard Behavior

  • Single Keypress: No need to press Enter, responds immediately to key
  • Default Handling: Press Enter to use default value
  • Case Insensitive: Both uppercase and lowercase letters work
  • VI Mode: Disabled by default for confirmation prompts
  • Escape/Ctrl+C: Triggers keyboard interrupt or returns None based on settings

Integration with Question Flow

Confirmation prompts are commonly used in conditional question flows:

from InquirerPy import prompt

questions = [
    {
        "type": "confirm",
        "message": "Do you want to configure advanced settings?",
        "name": "advanced",
        "default": False
    },
    {
        "type": "input", 
        "message": "Enter API endpoint:",
        "name": "endpoint",
        "when": lambda answers: answers["advanced"]
    },
    {
        "type": "confirm",
        "message": "Confirm settings?",
        "name": "confirm_save",
        "default": True
    }
]

answers = prompt(questions)

Install with Tessl CLI

npx tessl i tessl/pypi-inquirerpy

docs

advanced-prompts.md

classic-api.md

confirmation.md

index.md

selection.md

text-input.md

utilities.md

tile.json