Toggle
An inline switch that cycles between a fixed set of labeled values. It collects the selected option value (a string). It's always in one of its states, so it always returns a value.
$p->toggle('ripeness', 'Ripeness')
->options([
'ripe' => 'Ripe', // value => label
'unripe' => 'Unripe',
])
->default('ripe'); // Which value starts selected (defaults to the first).
Runnable script: playground/02-widgets-toggle.php.
Options
| Name | Description | Required | Default |
|---|---|---|---|
options() | The values to switch between, as a value => label map. | Yes | - |
default() | Which value starts selected. | No | First option |
Keyboard
| Key | Action |
|---|---|
| ← / → / Space / ↑ / ↓ | Cycle to the adjacent value |
| a letter | Jump to the first value whose label starts with it |
| Enter | Accept the current value |
| Esc | Cancel |
Display modes
In all four display modes - Unicode or ASCII, color on or off:
| ANSI | No ANSI | |
| Unicode | ||
| ASCII |