Documentation
¶
Overview ¶
Package config defines the types that allow any Model to contribute configurable fields to the application's Settings page.
Usage pattern:
- A component (page, nav, logger) implements Configurable.
- It returns a Section describing its fields with pointers into its own state for live binding.
- The router collects sections and passes them to [settings.New].
- Settings builds one huh.Form group per section; Tab cycles naturally through every field in every section with no custom pane-switch code.
Index ¶
- type Configurable
- type FieldDef
- func BoolField(key, title, description string, value *string, apply func(string) error) FieldDef
- func EnumField(key, title, description string, options []huh.Option[string], value *string, ...) FieldDef
- func TextField(key, title, description string, value *string, validate func(string) error, ...) FieldDef
- func YesNoField(key, title, description string, value *string, apply func(string) error) FieldDef
- type FieldKind
- type Section
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Configurable ¶
type Configurable interface {
ConfigSection() Section
}
Configurable can be implemented by any page model or router component that wants to expose its configuration in the Settings page. The router discovers Configurable implementations and passes their Sections to settings.New so they appear after the built-in sections.
type FieldDef ¶
type FieldDef struct {
// Key is a machine-readable identifier, used for JSON persistence.
Key string
// Title is the label rendered above the input.
Title string
// Description is an optional helper line rendered below the label when
// the field is focused. It is muted/hidden when the field is blurred.
Description string
// Kind determines which huh widget is created.
Kind FieldKind
// Options is the ordered list of choices for FieldSelect widgets.
Options []huh.Option[string]
// Value must point to the string field in the owning model that backs
// this setting. The pointer must remain valid for the lifetime of the
// Settings page.
Value *string
// Height overrides the drop-down height for FieldSelect (0 = huh default).
Height int
// DirAllowed and FileAllowed configure FieldFilePicker.
DirAllowed bool
FileAllowed bool
// HideFunc, when non-nil, is called before rendering to decide whether
// this field should be skipped. Returning true hides the field.
HideFunc func() bool
// Validate is an optional per-field validation function called when the
// user moves focus away from the field.
Validate func(string) error
// Apply is an optional callback run when a field edit is submitted.
// Use this to persist values outside tui-base settings storage.
Apply func(string) error
}
FieldDef describes one configurable value that a component exposes to the Settings page. Settings turns each FieldDef into the corresponding huh widget and keeps it live-bound to the component's own field via the Value pointer.
func BoolField ¶ added in v0.1.2
BoolField returns a FieldSelect FieldDef with Enabled/Disabled options bound to a *string field that holds "true" or "false". The apply callback is called when the user submits the form; pass nil to skip the callback.
func EnumField ¶ added in v0.1.2
func EnumField(key, title, description string, options []huh.Option[string], value *string, apply func(string) error) FieldDef
EnumField returns a FieldSelect FieldDef with arbitrary label/value pairs.
type Section ¶
type Section struct {
// Title is displayed as the section heading inside the Settings form.
Title string
// Fields is the ordered list of configurable values in this section.
Fields []FieldDef
}
Section groups related FieldDefs under a named heading. Each Section becomes one huh.Group in the Settings form.