field

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2026 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package field is one editable settings row: a label plus either free text (KindText, wrapping bubbles/textinput) or a cycled value from a closed set (KindChoice, no textinput at all - so an invalid value is unreachable, not merely rejected). This is the only editing primitive the settings screen has; there is no separate multi-field form type until a second section needs one.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Kind

type Kind int

Kind selects a field's editing shape.

const (
	KindText Kind = iota
	KindChoice
)

type Model

type Model struct {
	Theme theme.Theme
	Tier  theme.Tier
	// contains filtered or unexported fields
}

Model is one field. Theme/Tier are exported like picker.Model's own fields; SetTheme exists anyway (not a bare assignment) because KindText's embedded textinput carries hard-coded styles bubbles ships with, and forgetting to restyle it is exactly the composer.go:79-96 bug this package must not repeat.

func New

func New(t theme.Theme, tier theme.Tier, label string, kind Kind, width int) Model

New builds a field. width is the full row width available for the value; KindText clamps its input to it, KindChoice ignores it (a single value never wraps).

func (*Model) Blur

func (m *Model) Blur()

func (*Model) Cycle

func (m *Model) Cycle(delta int)

Cycle moves a KindChoice field to the next (delta>0) or previous (delta<0) value, wrapping. A no-op on KindText.

func (*Model) Focus

func (m *Model) Focus() tea.Cmd

Focus arms the field for input. KindText forwards to textinput's own Focus (which returns the cursor-blink Cmd); KindChoice has nothing to focus beyond the marker its owner draws.

func (Model) Focused

func (m Model) Focused() bool

func (*Model) SetChoices

func (m *Model) SetChoices(choices []string, active string)

SetChoices sets a KindChoice field's closed value set and starts the cursor on active (or the first choice if active matches none).

func (*Model) SetTheme

func (m *Model) SetTheme(t theme.Theme, tier theme.Tier)

SetTheme restyles the field, including KindText's embedded textinput - see the package doc for why this cannot be a bare field assignment.

func (*Model) SetValidate

func (m *Model) SetValidate(f func(string) error)

SetValidate injects the field's validation rule. A KindEnvName-style variant is not a separate Kind: the POSIX env-var check, the positive-int check, and every other rule this screen needs are a few lines each, injected here.

func (*Model) SetValue

func (m *Model) SetValue(v string)

SetValue sets a KindText field's starting text.

func (*Model) SetWidth

func (m *Model) SetWidth(w int)

func (Model) Update

func (m Model) Update(msg tea.Msg) (Model, tea.Cmd)

Update forwards a key to the embedded textinput while a KindText field is focused. KindChoice never reaches here: its owner drives Cycle directly, since there is no free-text buffer to route keys into.

func (Model) Validate

func (m Model) Validate() error

Validate runs the injected rule against the current value. A field with no injected rule is always valid.

func (Model) Value

func (m Model) Value() string

Value is the field's current value: the input text for KindText, the selected choice for KindChoice.

func (Model) View

func (m Model) View() string

View renders "label value", the value reverse-videoed while focused - the same marker-free focus convention picker.View() uses, so a field row and a picker row read as the same kind of thing.

Jump to

Keyboard shortcuts

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