Prompt for multiple named fields

SolidGroundUX DocumentationSolidGroundUX
NL

fn: ask_prompt_form

Purpose

Prompt the user for a list of field specifications and assign each response to its target variable.

Behavior

  • Accepts field specifications in KEY|LABEL|DEFAULT|VALIDATOR format.
  • Uses the current variable value as the editable default when available.
  • Falls back to the field default when the target variable is empty.
  • Optionally auto-aligns labels based on the widest field label.
  • Skips invalid shell variable names with a warning.

Options

  • --labelwidth WIDTH — Visible label width for all fields.
  • --autoalign — Calculates label width from the supplied field labels.
  • --colorize MODE — Colorize mode passed to ask.
  • --pad COUNT — Number of spaces inserted before each prompt label.
  • --labelclr ANSI — ANSI sequence used for labels.
  • --inputclr ANSI — ANSI sequence used for input.

Arguments

  • FIELD_SPEC... — One or more KEY|LABEL|DEFAULT|VALIDATOR records.

Outputs (globals)

Variables named by the KEY component of each valid field specification.

Returns

  • 0 after all valid fields have been prompted.

Usage

  # Auto-align two validated fields.
  ask_prompt_form --autoalign \
      "TARGET_DIR|Target directory|/tmp|sgnd_validate_dir_exists" \
      "RETRY_COUNT|Retry count|3|sgnd_validate_int"

  # Supply a fixed label width and editable defaults.
  ask_prompt_form --labelwidth 24 \
      "HOST|Database host|localhost|" \
      "PORT|Database port|5432|sgnd_validate_int"