Skip to main content

Select

Select widgetSelect widget

Single choice from a list of options. It collects the selected option value (a string).

$p->select('fruit', 'Fruit')
->options([
'apple' => 'Apple',
'banana' => 'Banana',
'cherry' => 'Cherry',
])
->default('banana') // Which option starts highlighted (defaults to the first).
->pageSize(10); // Options visible before the list pages around the cursor.

Options

NameDescriptionRequiredDefault
options()The choices, as a value => label map (or added one at a time with option()).Yes-
default()Which option starts highlighted, by value.NoFirst option
pageSize()Options shown before the list pages around the cursor.No10

For headings, separators and disabled options, see Option groups.

Keyboard

KeyAction
/ Move the highlight (skips headings, separators and disabled options)
EnterAccept the highlighted option
EscCancel

Display modes

In all four display modes - Unicode or ASCII, colour on or off:

ANSINo ANSI
UnicodeSelect: Unicode + ANSISelect: Unicode + ANSISelect: Unicode + No ANSISelect: Unicode + No ANSI
ASCIISelect: ASCII + ANSISelect: ASCII + ANSISelect: ASCII + No ANSISelect: ASCII + No ANSI