field

package
v0.265.0 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2026 License: MIT Imports: 7 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 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 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) Completed

func (f *Form) Completed() bool

Completed reports whether a submit passed validation.

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

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

Init focuses the first field.

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

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

func (f *Form) SetWidth(w int)

SetWidth sizes every input to the available content width.

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.

Jump to

Keyboard shortcuts

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