VOOZH about

URL: https://deepwiki.com/hypervel/prompts/5-interactive-prompts

⇱ Interactive Prompts | hypervel/prompts | DeepWiki


Loading...
Last indexed: 7 February 2026 (2e2181)
Menu

Interactive Prompts

Purpose and Scope

Interactive prompts are user input components that pause program execution to collect information from the terminal user. This page provides an overview of all 10 interactive prompt types available in the library, their characteristics, and guidance on selecting the appropriate prompt for different scenarios.

For implementation details of specific prompt categories, see:

For the foundational prompt lifecycle and state management that all interactive prompts share, see The Prompt Lifecycle and State Management and Validation.

Sources: High-level architecture diagrams (Diagram 2: Prompt Type Taxonomy)


Interactive Prompt Taxonomy

The library provides 10 interactive prompt types organized into four functional categories:

Interactive Prompt Type Hierarchy


Sources: src/helpers.php10-133 Diagram 2 from architecture overview


Prompt Type Comparison

Prompt TypeHelper FunctionUse CaseInput MethodReturn TypeKey Features
TextPrompttext()Single-line text inputFree-form typingstringPlaceholder, default value
TextareaPrompttextarea()Multi-line text inputMulti-line editingstringConfigurable row count
PasswordPromptpassword()Sensitive text inputMasked typingstringHidden characters
SelectPromptselect()Choose one from listArrow key navigationint|stringScrolling, default selection
MultiSelectPromptmultiselect()Choose multiple from listArrow keys + spacebararray<int|string>Multiple defaults, scrolling
ConfirmPromptconfirm()Yes/No decisionY/N or arrow keysboolCustomizable labels
SuggestPromptsuggest()Text with autocompleteTyping with suggestionsstringStatic or dynamic options
SearchPromptsearch()Choose one via searchType to filter optionsint|stringDynamic option generation
MultiSearchPromptmultisearch()Choose multiple via searchType to filter + spacebararray<int|string>Dynamic filtering
PausePromptpause()Wait for user acknowledgmentPress EnterboolNo input required

Sources: src/helpers.php10-133


Helper Function to Prompt Class Mapping

Each interactive prompt is accessible through a global helper function that instantiates the corresponding prompt class and invokes its prompt() method:

Helper Function Instantiation Pattern


Each helper function follows this pattern:


Sources: src/helpers.php40-50 src/helpers.php53-64 src/helpers.php109-119


Common Features Across Interactive Prompts

All interactive prompts share a consistent set of features, though not every feature is available on every prompt type:

Validation

Most prompts accept a $validate parameter that can be:

  • A Closure accepting the input value and returning an error message string on failure
  • A validation rule string or array (implementation-dependent)
  • null to skip validation

Transformation

The $transform parameter accepts a Closure that modifies the returned value after successful submission:


Required Fields

The $required parameter controls whether empty input is allowed:

  • true: Field is required (default for most prompts)
  • false: Field is optional
  • string: Field is required with custom error message

Note: SelectPrompt and SearchPrompt only accept true or a string, never false.

Default Values

Most prompts support default values that are pre-populated or pre-selected:

  • Text prompts: Pre-fill the input field
  • Selection prompts: Highlight the default option
  • Multi-selection prompts: Pre-check multiple options

Hints

The $hint parameter displays additional context below the prompt label, useful for providing instructions or examples.

Sources: src/SelectPrompt.php27-36 src/helpers.php14-17 src/helpers.php47-50


Basic Usage Patterns

Pattern 1: Simple Text Collection


Pattern 2: Selection from Options


Pattern 3: Multiple Selection


Pattern 4: Dynamic Search


Pattern 5: Confirmation


Sources: src/helpers.php14-17 src/helpers.php47-50 src/helpers.php61-64 src/helpers.php116-119 src/helpers.php71-74


Scrolling Behavior in List-Based Prompts

Three prompt types utilize the Scrolling trait for viewport management when displaying long option lists:

Scrolling-Enabled Prompts


The $scroll parameter controls how many options are visible simultaneously:


When the user navigates beyond the visible window, the viewport automatically adjusts to keep the highlighted option visible.

Sources: src/SelectPrompt.php13 src/SelectPrompt.php31 src/SelectPrompt.php96-99 Diagram 5 from architecture overview


Key Input Handling

All interactive prompts respond to keyboard input through an event-based system. Common key bindings include:

Key(s)ActionApplicable Prompts
EnterSubmit current valueAll prompts
Ctrl+CCancel promptAll prompts
/ / j / kNavigate optionsSelect, MultiSelect, Search
Home / End / Ctrl+A / Ctrl+EJump to first/lastSelect, MultiSelect, Search
SpaceToggle selectionMultiSelect, MultiSearch
Tab / Shift+TabNavigate (forward/backward)Select prompts
Ctrl+URevert to previous stepForm contexts

Example key handler registration from SelectPrompt:

src/SelectPrompt.php55-62

Sources: src/SelectPrompt.php55-62


State Management

All interactive prompts follow the same state lifecycle, transitioning through these states:

  1. Initial: Before first render
  2. Active: Awaiting user input
  3. Error: Validation failed, displaying error message
  4. Submit: User confirmed input (Enter key)
  5. Cancel: User cancelled prompt (Ctrl+C)

The prompt's state determines how it is rendered by the theme-specific renderer. For detailed information on state transitions and the rendering pipeline, see The Prompt Lifecycle and State Management and Validation.

Sources: Diagram 3 from architecture overview, Core Architecture page


Options Format

Selection-based and search-based prompts accept options in two formats:

Format 1: List Array (Values as Options)


Format 2: Associative Array (Keys as Values)


The SelectPrompt::value() method determines which format is in use:

src/SelectPrompt.php68-78

Options Format Detection


Sources: src/SelectPrompt.php68-78 src/SelectPrompt.php74-77


Hyperf Collection Support

All prompts that accept arrays also accept Hyperf\Collection\Collection instances:


Collections are automatically converted to arrays:

src/SelectPrompt.php41

Sources: src/SelectPrompt.php25 src/SelectPrompt.php41 src/helpers.php8


Return Values

Interactive prompts return typed values based on their purpose:

Prompt TypeReturn TypeExample Values
Text-basedstring"John Doe", ""
SelectPromptint|string"red" (list), 1 (associative)
MultiSelectPromptarray<int|string>["red", "blue"], [1, 3, 5]
ConfirmPromptbooltrue, false
SearchPromptint|stringSame as SelectPrompt
MultiSearchPromptarray<int|string>Same as MultiSelectPrompt
PausePromptbooltrue (continued), false (cancelled)

Sources: src/SelectPrompt.php68-78 src/helpers.php47 src/helpers.php61 src/helpers.php71


Non-Interactive Fallback

When running in non-interactive environments (e.g., CI pipelines), prompts automatically return default values without blocking for input. This behavior is controlled by the Prompt::$interactive static property.

For details on fallback mechanisms and environment detection, see Fallback Implementations and Interactivity.

Sources: src/SelectPrompt.php70-72


Next Steps

For detailed documentation of each prompt category:

For integrating prompts into multi-step workflows, see Multi-Step Forms with FormBuilder.

Sources: Table of contents structure