fn: ask_decision
Purpose
Prompt the user for a constrained decision and store the canonical result.
Behavior
- Displays the configured decision choices next to the prompt by default.
- Accepts aliases such as YES|Y or NO|N and stores the canonical value.
- Can auto-continue after a timeout and map redo/cancel keys to decisions.
- Re-prompts until the entered value matches the configured choice list.
Options
--label TEXT— Prompt text displayed to the user.--choices SPEC— Comma-separated canonical/alias groups, e.g. "YES|Y,NO|N".--default VALUE— Default decision used for empty input or timeout mapping.--var NAME— Shell variable that receives the canonical decision. Defaults to decision.--seconds COUNT— Optional auto-continue countdown before falling back to typed input.--displaychoices 0|1— Controls whether the compact choice list is shown in the prompt.--labelwidth WIDTH— Visible width used to align the prompt label.--pad COUNT— Number of spaces inserted before the prompt label.--labelclr ANSI— ANSI sequence used for the label.--inputclr ANSI— ANSI sequence used for the input.--colorize MODE— Colorize mode passed to ask.
Outputs (globals)
Variable named by --var.
Returns
- 0 when a canonical decision was stored.
Usage
# Present Yes/No/Cancel aliases and store a canonical decision.
ask_decision --label "Install now" \
--choices "YES|Y,NO|N,CANCEL|C" \
--default "YES" \
--var decision
# Use the short countdown mode, without listing choices in the prompt.
ask_decision --label "Continue?" \
--choices "CONTINUE|C,CANCEL|Q" --default CONTINUE \
--seconds 5 --displaychoices 0 --var next_action
