form

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 12, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var KEY_LEFT = key.NewBinding(
	key.WithKeys("left"),
	key.WithHelp("←", "left"),
)

Keybinding for moving the choosen item to right

View Source
var KEY_RIGHT = key.NewBinding(
	key.WithKeys("right"),
	key.WithHelp("→", "right"),
)

Keybinding for moving the choosen item to right

Functions

This section is empty.

Types

type Form

type Form struct {
	// Items
	Items []FormItemWrapped

	// Focused index
	FocusedIndex int

	// Default values
	Default map[string]string
}

func New

func New() Form

Initializes a new form item

func (*Form) AddInput

func (form *Form) AddInput(id, title, desc string, input textinput.Model, validators []Validator)

Adds a new input to the form

func (*Form) AddOption

func (form *Form) AddOption(id, title, desc string, options []string)

Adds a new input to the form

func (*Form) Disable

func (form *Form) Disable(id string)

Disables a form item

func (*Form) Enable

func (form *Form) Enable(id string)

Enables a form item

func (*Form) FocusedItem

func (form *Form) FocusedItem() FormItem

Returns the focused form item

func (*Form) PostInit

func (form *Form) PostInit()

Runs the post init hook

func (*Form) Update

func (form *Form) Update(msg tea.Msg, vault *tlockvault.Vault) tea.Cmd

Updates

type FormItem

type FormItem interface {
	// Handle messages
	Update(msg tea.Msg) tea.Cmd

	// View
	View() string

	// Focus
	Focus()

	// Unfocus
	Unfocus()

	// Returns the value
	Value() string

	// Sets the error message
	// Nil means to remove the error
	SetError(err *error)
}

Interface that every form item must implement Form item

type FormItemInputBox

type FormItemInputBox struct {
	// Title
	Title string

	// Description
	Description string

	// Input box
	Input textinput.Model

	// Error message
	ErrorMessage *error
}

Form item for input boxes

func (*FormItemInputBox) Focus

func (item *FormItemInputBox) Focus()

Focus

func (*FormItemInputBox) SetError

func (item *FormItemInputBox) SetError(err *error)

SetError

func (*FormItemInputBox) Unfocus

func (item *FormItemInputBox) Unfocus()

Unfocus

func (*FormItemInputBox) Update

func (item *FormItemInputBox) Update(msg tea.Msg) tea.Cmd

Update

func (FormItemInputBox) Value

func (item FormItemInputBox) Value() string

Value

func (FormItemInputBox) View

func (item FormItemInputBox) View() string

View

type FormItemOptionBox

type FormItemOptionBox struct {
	// Title
	Title string

	// Description
	Description string

	// Input box
	Values []string

	// Selected value
	SelectedIndex int

	// Error message
	Focused bool
}

Form item for option box

func (*FormItemOptionBox) Focus

func (item *FormItemOptionBox) Focus()

Focus

func (FormItemOptionBox) SetError

func (item FormItemOptionBox) SetError(err *error)

SetError

func (*FormItemOptionBox) Unfocus

func (item *FormItemOptionBox) Unfocus()

Unfocus

func (*FormItemOptionBox) Update

func (item *FormItemOptionBox) Update(msg tea.Msg) tea.Cmd

Update

func (FormItemOptionBox) Value

func (item FormItemOptionBox) Value() string

Value

func (FormItemOptionBox) View

func (item FormItemOptionBox) View() string

View

type FormItemWrapped

type FormItemWrapped struct {
	// ID
	ID string

	// Form item
	FormItem FormItem

	// Is it enabled
	Enabled bool

	// Validators
	Validators []Validator
}

Form item wrapped

type FormSubmittedMsg

type FormSubmittedMsg struct {
	Data map[string]string
}

Message that represents that the form is submitted and the items pass the validators

type Validator

type Validator = func(vault *tlockvault.Vault, value string) error

Validator

Jump to

Keyboard shortcuts

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