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) Carets() []int
- func (f *Form) Completed() bool
- func (f *Form) Cursor(i int) int
- func (f *Form) FocusIndex(i int) tea.Cmd
- func (f *Form) FocusedIndex() int
- func (f *Form) FocusedLabel() string
- func (f *Form) Init() tea.Cmd
- func (f *Form) Insert(i int, text string)
- func (f *Form) Reset()
- func (f *Form) Resume()
- func (f *Form) SetCarets(carets []int)
- func (f *Form) SetCursor(i, pos int)
- func (f *Form) SetHeight(h int)
- func (f *Form) SetHighlight(c color.Color)
- func (f *Form) SetValues(vals []string)
- func (f *Form) SetVisible(i int, visible bool)
- func (f *Form) SetWidth(w int)
- func (f *Form) Source(i int) string
- func (f *Form) Update(msg tea.Msg) tea.Cmd
- func (f *Form) Values() []string
- func (f *Form) View() string
- func (f *Form) Visible(i int) bool
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 multi-line text area, a two-choice toggle, or a cycle-through select.
func NewArea ¶ added in v0.268.0
NewArea returns a multi-line text field, for values such as expressions whose line breaks are part of what was written: a text field would join the lines. alt+enter (or shift+enter, ctrl+j) starts a new line; enter moves on, as in every other field. It grows with its value, up to areaMaxRows rows.
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) Carets ¶ added in v0.268.0
Carets reports every field's caret, in field order; non-text fields have no caret and report 0. Pair it with SetCarets to carry carets across a rebuild: a form built from scratch starts every caret at 0.
func (*Form) Cursor ¶ added in v0.268.0
Cursor reports the caret's rune offset within field i, so a caller can see what it is about to Insert into. Non-text fields have no caret and report 0.
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) FocusedLabel ¶ added in v0.268.0
FocusedLabel returns the label of the focused field.
func (*Form) Insert ¶ added in v0.268.0
Insert splices text into field i at its caret, leaving the caret after the inserted text so the user can keep typing where they left off.
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) SetCarets ¶ added in v0.268.0
SetCarets restores carets saved by Carets, in field order. Each one is clamped to its field's current value; extra entries are ignored and missing ones leave the field's caret where it is.
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) SetVisible ¶ added in v0.268.0
SetVisible shows or hides a field. Hidden fields are skipped by focus movement and omitted from View, but keep their value so unhiding restores it.
func (*Form) Source ¶ added in v0.268.0
Source is field i's value to write back: what SetValues gave it until the user edits it, then what it holds. A field shows its value sanitized, so writing back what it shows would rewrite text nobody touched.
func (*Form) Update ¶
Update routes keys: tab/down and shift+tab/up cycle, enter submits, everything else edits the focused field.
func (*Form) Values ¶
Values returns every field's current value, in field order (toggles as "true"/"false").