Documentation
¶
Overview ¶
Package field provides a minimal themed form: labeled text inputs with an accent bar on focus, inline validation, tab-cycled focus, and enter-to-submit. It replaces huh, which pinned bubbletea v1 and capped the visual ceiling.
Index ¶
- type Field
- type Form
- func (f *Form) Completed() bool
- func (f *Form) FocusIndex(i int) tea.Cmd
- func (f *Form) FocusedIndex() int
- func (f *Form) Init() tea.Cmd
- func (f *Form) Reset()
- func (f *Form) Resume()
- func (f *Form) SetHeight(h int)
- func (f *Form) SetHighlight(c color.Color)
- func (f *Form) SetValues(vals []string)
- func (f *Form) SetWidth(w int)
- func (f *Form) Update(msg tea.Msg) tea.Cmd
- func (f *Form) Values() []string
- func (f *Form) View() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Field ¶
type Field struct {
// contains filtered or unexported fields
}
Field is one labeled input: a text entry, a two-choice toggle, or a cycle-through select.
func NewSelect ¶
NewSelect returns a field that cycles through options with ←→ or space; its value is the selected option string.
func NewToggle ¶
NewToggle returns a two-choice toggle field (◉ on / ○ off). Space or ←→ flip the choice; its value is "true"/"false".
type Form ¶
type Form struct {
// contains filtered or unexported fields
}
Form owns focus order and completion state for its fields.
func (*Form) FocusIndex ¶
FocusIndex focuses the field at index i (clamped), blurring the current one. Used to keep the cursor on a control across a form rebuild.
func (*Form) FocusedIndex ¶ added in v0.267.0
FocusedIndex returns the index of the currently focused field. Used to capture focus before a form rebuild so it can be restored via FocusIndex.
func (*Form) Reset ¶
func (f *Form) Reset()
Reset clears values, errors, and completion, refocusing the first field.
func (*Form) Resume ¶
func (f *Form) Resume()
Resume reopens a completed form without discarding its values, allowing application-level validation errors to be corrected in place.
func (*Form) SetHeight ¶
SetHeight clamps the rendered form to a scrolling window. The window follows the focused field, including its inline validation error when possible.
func (*Form) SetHighlight ¶
SetHighlight sets the background that marks the focused field's row (label + input). Unfocused fields render with no background so only the active field is emphasized. The focused input carries the same background so its row fills cleanly; blurred inputs stay transparent.
func (*Form) SetValues ¶
SetValues fills each field with the corresponding entry in vals, in field order. Bounds-safe: extra vals are ignored, missing ones leave the field untouched.
func (*Form) Update ¶
Update routes keys: tab/down and shift+tab/up cycle, enter submits, everything else edits the focused field.