field

package
v0.270.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 6, 2026 License: MIT Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

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 New

func New(label, placeholder string) *Field

New returns a text field with the given label and placeholder.

func NewArea added in v0.268.0

func NewArea(label, placeholder string) *Field

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

func NewSelect(label string, options []string, initial int) *Field

NewSelect returns a field that cycles through options with ←→ or space; its value is the selected option string.

func NewToggle

func NewToggle(label, onLabel, offLabel string, on bool) *Field

NewToggle returns a two-choice toggle field (◉ on / ○ off). Space or ←→ flip the choice; its value is "true"/"false".

func (*Field) Secret

func (f *Field) Secret() *Field

Secret marks a text field as sensitive: its value is echoed as a dot mask while typing so API tokens and client secrets are never shown in cleartext. No-op on non-text fields.

func (*Field) WithValidate

func (f *Field) WithValidate(fn func(string) error) *Field

WithValidate attaches a validation function, run on submit.

type Form

type Form struct {
	// contains filtered or unexported fields
}

Form owns focus order and completion state for its fields.

func NewForm

func NewForm(fields ...*Field) *Form

NewForm builds a form; the first field takes focus on Init.

func (*Form) Carets added in v0.268.0

func (f *Form) Carets() []int

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) Completed

func (f *Form) Completed() bool

Completed reports whether a submit passed validation.

func (*Form) Cursor added in v0.268.0

func (f *Form) Cursor(i int) int

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

func (f *Form) FocusIndex(i int) tea.Cmd

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

func (f *Form) FocusedIndex() int

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

func (f *Form) FocusedLabel() string

FocusedLabel returns the label of the focused field.

func (*Form) Init

func (f *Form) Init() tea.Cmd

Init focuses the first field.

func (*Form) Insert added in v0.268.0

func (f *Form) Insert(i int, text string)

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

func (f *Form) SetCarets(carets []int)

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) SetCursor added in v0.268.0

func (f *Form) SetCursor(i, pos int)

SetCursor moves the caret within a field's text.

func (*Form) SetHeight

func (f *Form) SetHeight(h int)

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

func (f *Form) SetHighlight(c color.Color)

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

func (f *Form) SetValues(vals []string)

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

func (f *Form) SetVisible(i int, visible bool)

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) SetWidth

func (f *Form) SetWidth(w int)

SetWidth sizes every input to the available content width.

func (*Form) Source added in v0.268.0

func (f *Form) Source(i int) string

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

func (f *Form) Update(msg tea.Msg) tea.Cmd

Update routes keys: tab/down and shift+tab/up cycle, enter submits, everything else edits the focused field.

func (*Form) Values

func (f *Form) Values() []string

Values returns every field's current value, in field order (toggles as "true"/"false").

func (*Form) View

func (f *Form) View() string

View renders fields stacked: label, input, optional error. The focused field's whole row (label + input) is filled with the highlight; the others render plain so only the active field is emphasized.

func (*Form) Visible added in v0.268.0

func (f *Form) Visible(i int) bool

Visible reports whether a field is shown.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL