Skip to main content

Module form

Module form 

Source
Expand description

Multi-field input form with a stable two-column layout.

Two entry points:

  1. High-level: build a FormState from a list of FormField, route keys through FormState::handle_key, and render with render_form. Suitable for self-contained settings/wizard-style screens.

  2. Low-level primitives: label_prefix, input_row, select_row, error_lines. Use these when you want the same visual style but manage focus/buffer state yourself (e.g. ygg’s blueprint detail panel, which stores its form values inside a snapshot-backed buffer).

§Visual language

  • label value ← row, inactive
  • label [ lhs│rhs ] ← row, active, software caret
  • label ◀ option ▶ ← row, active, enum / bool cycle
  • label * value ← row with validation error (red *)
  • └ message wrapped over… ← per-row error, red italic
  • …more text ← continuation, aligned under message

The caret is drawn in-band (software cursor). Hide the terminal’s hardware cursor (Frame::set_cursor_position omitted) so only one caret is visible.

Structs§

FormField
One row in a form.
FormState
Form state: fields + focus + per-field cursor + touched set.
FormStyle
Styling knobs for render_form.

Enums§

FieldInput
The interactive value held by a FormField.
FormEvent
Outcome of routing a key through FormState::handle_key.

Functions§

error_lines
Render a per-row inline error message, wrapped to max_width. The first line is prefixed with , continuations with two spaces so the message text stays aligned. Indented by indent columns so it sits under the row’s label.
input_row
Render a text-input row.
label_prefix
Build the label-column spans for a row. Output: " <label><*|space><filler>" — two-space left indent, label, then a red bold * if error is true (else a space), padded so all values line up at column indent + 2 + pad + 2.
render_form
Render a form inside area, applying the default styling.
render_form_with
Render a form with explicit style options and per-field errors.
select_row
Render a select-style row: when active, the value is framed with ◀ … ▶ cycle glyphs. When inactive, it renders plain.
wrap_chars
Word-wrap s into chunks of at most width chars each. Breaks on whitespace; hard-breaks words longer than width.