tuicore

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package tuicore provides shared TUI form components for CLI commands.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConfigState

type ConfigState struct {
	Current *config.Config
	Dirty   map[string]bool
}

ConfigState holds the current configuration state and tracking for dirty fields.

func NewConfigState

func NewConfigState() *ConfigState

NewConfigState creates a new state with default config.

func NewConfigStateWith

func NewConfigStateWith(cfg *config.Config) *ConfigState

NewConfigStateWith creates a new state with the given config.

func (*ConfigState) IsDirty

func (s *ConfigState) IsDirty(field string) bool

IsDirty checks if a field is modified.

func (*ConfigState) MarkDirty

func (s *ConfigState) MarkDirty(field string)

MarkDirty marks a field as modified.

func (*ConfigState) UpdateAuthProviderFromForm

func (s *ConfigState) UpdateAuthProviderFromForm(id string, form *FormModel)

UpdateAuthProviderFromForm updates a specific OIDC provider config from the form.

func (*ConfigState) UpdateConfigFromForm

func (s *ConfigState) UpdateConfigFromForm(form *FormModel)

UpdateConfigFromForm updates the config based on the form fields.

func (*ConfigState) UpdateMCPServerFromForm added in v0.4.0

func (s *ConfigState) UpdateMCPServerFromForm(name string, form *FormModel)

UpdateMCPServerFromForm updates a specific MCP server config from the form.

func (*ConfigState) UpdateProviderFromForm

func (s *ConfigState) UpdateProviderFromForm(id string, form *FormModel)

UpdateProviderFromForm updates a specific provider config from the form.

type Field

type Field struct {
	Key         string
	Label       string
	Description string // Help text shown below the focused field
	Type        InputType
	Value       string
	Placeholder string
	Options     []string // For InputSelect and InputSearchSelect
	Checked     bool     // For InputBool
	Width       int
	Validate    func(string) error

	// VisibleWhen controls conditional visibility. When non-nil, the field is
	// shown only when this function returns true. When nil the field is always visible.
	VisibleWhen func() bool

	// OnChange is called when the field value changes (e.g. InputSelect left/right).
	// The returned tea.Cmd (if non-nil) is executed asynchronously by the runtime.
	OnChange func(newValue string) tea.Cmd

	// Loading indicates an async operation (e.g. model fetch) is in progress.
	Loading bool
	// LoadError holds the last async fetch error for display.
	LoadError error

	// TextInput holds the bubbletea text input model (exported for cross-package use).
	TextInput textinput.Model
	Err       error

	// InputSearchSelect state
	FilteredOptions []string // Filtered subset of Options
	SelectCursor    int      // Cursor position in filtered list
	SelectOpen      bool     // Whether dropdown is open
}

Field represents a single configuration field in a form.

func (*Field) IsVisible

func (f *Field) IsVisible() bool

IsVisible reports whether this field should be rendered and navigable.

type FieldOptionsLoadedMsg added in v0.4.0

type FieldOptionsLoadedMsg struct {
	FieldKey   string   // target field Key
	ProviderID string   // provider at request time (race-condition guard)
	Options    []string // fetched options (nil on error)
	Err        error    // fetch error, if any
}

FieldOptionsLoadedMsg is sent when an asynchronous model fetch completes. ProviderID is recorded at request time so stale results (from a previously selected provider) can be safely ignored.

type FormModel

type FormModel struct {
	Title    string
	Fields   []*Field
	Cursor   int // index into VisibleFields()
	Focus    bool
	OnSave   func(map[string]interface{})
	OnCancel func()
}

FormModel manages a list of fields.

func NewFormModel

func NewFormModel(title string) FormModel

NewFormModel creates a new form with the given title.

func (*FormModel) AddField

func (m *FormModel) AddField(f *Field)

AddField adds a field to the form, initializing its text input if applicable.

func (FormModel) HasOpenDropdown

func (m FormModel) HasOpenDropdown() bool

HasOpenDropdown reports whether any field has an open search-select dropdown.

func (FormModel) Init

func (m FormModel) Init() tea.Cmd

Init implements tea.Model.

func (FormModel) Update

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

Update implements tea.Model.

func (FormModel) View

func (m FormModel) View() string

View renders the form.

func (FormModel) VisibleFields

func (m FormModel) VisibleFields() []*Field

VisibleFields returns only the fields that pass their visibility check.

type InputType

type InputType int

InputType defines the type of input field.

const (
	InputText InputType = iota
	InputInt
	InputBool // Toggled via space
	InputSelect
	InputPassword
	InputSearchSelect // Searchable dropdown select
)

Jump to

Keyboard shortcuts

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