← All libraries

SugarReadline

SugarReadline

Interactive prompts — text, confirm, select, multi-select, textarea

port of erikgeiser/promptkit promptinputreadlineinteractive

Text, Confirm, Selection, MultiSelect, and Textarea prompts with full keyboard handling, filter-as-you-type, and pagination. State-machine model — no external readline dependency.

Install

composer require sugarcraft/sugar-readline

Quickstart

use SugarCraft\Readline\{TextPrompt, SelectionPrompt, MultiSelectPrompt};

// Text prompt
$name = TextPrompt::new('Your name:')->HandleChar('A')->Confirm()->Value();

// Selection prompt
$lang = SelectionPrompt::new('Pick a language:', ['PHP', 'Go', 'Rust', 'Python'])
    ->HandleKey('enter');

// Multi-select with constraints
$tools = MultiSelectPrompt::new('Pick tools:', ['vim', 'git', 'docker', 'php'])
    ->WithMinSelections(1)
    ->WithMaxSelections(3)
    ->HandleKey('space')
    ->HandleKey('enter');

What's in the box

TextPromptSingle-line input with placeholder, default value, password masking support.
ConfirmationPromptYes / No with customizable labels and default.
SelectionPromptArrow-key selection with filter-as-you-type and pagination.
MultiSelectPromptMulti-item selection with min/max enforcement, marker (◉/○), pagination.
TextareaPromptMulti-line editor with cursor movement, line count display.

Source & demos

Try the quickstart →

API

ClassMethodDescription
TextPromptnew(question)Create text prompt
TextPromptconfirm()Confirm input
ConfirmationPromptnew(question)Create yes/no prompt
SelectionPromptnew(question, options)Create selection prompt
MultiSelectPromptnew(question, options)Create multi-select prompt
MultiSelectPromptwithMinSelections(n)Set minimum selections
MultiSelectPromptwithMaxSelections(n)Set maximum selections
TextareaPromptnew(question)Create textarea prompt

Demos.

VHS-recorded GIFs of every example shipped with the library. Regenerated automatically on every push that touches the source.

Text prompt

Text prompt

Single-line text prompt with autocomplete.
Multi-select

Multi-select

Multi-select list with toggle + submit.