← All libraries

SugarPrompt

💬 SugarPrompt

Interactive forms — Note, Input, Confirm, Select, MultiSelect, Text, FilePicker

port of huh forms wizards validation

Form library built on CandyCore + SugarBits. Multi-page Group wizards, six themes, per-field validators, conditional skip predicates. The form is itself a Model — drop it into a Program.

Install

composer require candycore/sugar-prompt

Quickstart

use CandyCore\Prompt\Form;
use CandyCore\Prompt\Field\{Input, Confirm, Select, Note};

$form = Form::new(
    Note::new('welcome')
        ->withTitle('Onboarding')
        ->withDescription('A few quick questions.'),
    Input::new('name')
        ->withTitle('Your name?')
        ->withPlaceholder('Ada Lovelace')
        ->withValidate(fn($v) => strlen($v) >= 2 ? null : 'too short'),
    Confirm::new('newsletter')
        ->withTitle('Subscribe to the newsletter?'),
    Select::new('lang')
        ->withTitle('Favorite language?')
        ->withOptions('PHP', 'Go', 'Rust', 'Python'),
);
// $form is a CandyCore Model — drop it into a Program.

What's in the box

Field typesNote, Input, Confirm, Select, MultiSelect, Text, FilePicker.
Validation->withValidate(fn($v) => …) — return null to pass, error string to block submit.
Multi-page GroupsGroup::new() stacks Forms into a wizard. Conditional ->withSkipFn().
Six themesDefault, charm, dracula, base16, catppuccin, pink.
Tab navTab / Shift+Tab between fields, Enter on the last submits, Esc / Ctrl+C aborts.
Submit hook$form->getValue('name') after the Program ends — typed value retrieval.

Source & demos

Try the quickstart →

Demos.

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

Multi-page form

Multi-page form

Wizard across multiple Groups.
Input

Input

Single-line text with validation.
Confirm

Confirm

Y/N boolean.
Select

Select

Single-choice list.
MultiSelect

MultiSelect

Toggle multiple options.
Text

Text

Multi-line text input.
Themes

Themes

All six form themes side-by-side.