Toggle
An inline switch that flips between exactly two labeled values. It collects the selected option value (a string). It's always in one of its two 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-fields-toggle.php.
Options
| Name | Description | Required | Default |
|---|---|---|---|
options() | The two values to switch between, as a value => label map. A third is a build-time error. | Yes | - |
default() | Which value starts selected; a literal that is neither of the two is a build-time error. | No | First option |
Keyboard
| Key | Action |
|---|---|
| ← / → / Space / ↑ / ↓ | Flip to the other value |
| a letter | Jump to the 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 |