form

package
v2.0.7 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2022 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Start

func Start() tea.Msg

Start initiates the start of a form. Note that there is no implicit scoping of start messages to specific forms, proper routing of the start message is the responsibility of the enclosing model.

Types

type ChoiceField

type ChoiceField struct {
	choiceinput.Model

	Validator ChoiceFieldValidator
	// contains filtered or unexported fields
}

func NewChoiceField

func NewChoiceField() ChoiceField

func (*ChoiceField) Disable

func (m *ChoiceField) Disable()

func (*ChoiceField) Enable

func (m *ChoiceField) Enable()

func (ChoiceField) Enabled

func (m ChoiceField) Enabled() bool

func (ChoiceField) Hidden

func (m ChoiceField) Hidden() bool

func (*ChoiceField) Hide

func (m *ChoiceField) Hide()

func (*ChoiceField) SetEnabled

func (m *ChoiceField) SetEnabled(enabled bool)

func (*ChoiceField) SetHidden

func (m *ChoiceField) SetHidden(hidden bool)

func (*ChoiceField) Show

func (m *ChoiceField) Show()

func (ChoiceField) Update

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

func (ChoiceField) Validate

func (m ChoiceField) Validate() tea.Cmd

func (ChoiceField) View

func (m ChoiceField) View() string

type ChoiceFieldValidator

type ChoiceFieldValidator interface {
	ValidateChoiceField(value string) tea.Msg
}

type CompletionModel

type CompletionModel struct {
	// Returns the possible values given the current value of the model.
	Completions
	// contains filtered or unexported fields
}

CompletionModel is used to add completion functionality to another model via composition. If the completion function is set, it will enable tab completion via the update model (which must be given the current value of the model).

func (CompletionModel) Update

func (m CompletionModel) Update(msg tea.Msg, value string) (CompletionModel, tea.Msg)

Update the model and return the result. NOTE: we do not return a `tea.Cmd` because this is expected to run synchronously to avoid unexpected delays in the user interaction.

func (CompletionModel) View

func (m CompletionModel) View() string

type Completions

type Completions interface {
	Suggest(value string) []string
	View(suggestion string) string
}

type ContainerImage

type ContainerImage struct {
	Required string
	Valid    string
}

func (*ContainerImage) ValidateTextField

func (v *ContainerImage) ValidateTextField(value string) tea.Msg

type ExitField

type ExitField struct {
	Message string
	// contains filtered or unexported fields
}

func NewExitField

func NewExitField() ExitField

func (*ExitField) Blur

func (m *ExitField) Blur()

func (*ExitField) Disable

func (m *ExitField) Disable()

func (*ExitField) Enable

func (m *ExitField) Enable()

func (ExitField) Enabled

func (m ExitField) Enabled() bool

func (*ExitField) Focus

func (m *ExitField) Focus()

func (ExitField) Focused

func (m ExitField) Focused() bool

func (ExitField) Hidden

func (m ExitField) Hidden() bool

func (*ExitField) Hide

func (m *ExitField) Hide()

func (*ExitField) SetEnabled

func (m *ExitField) SetEnabled(enabled bool)

func (*ExitField) SetHidden

func (m *ExitField) SetHidden(hidden bool)

func (*ExitField) Show

func (m *ExitField) Show()

func (ExitField) Update

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

func (ExitField) Validate

func (m ExitField) Validate() tea.Cmd

func (ExitField) View

func (m ExitField) View() string

type Field

type Field interface {
	// Enable this field. Enabled fields can receive focus for updates and will be included in views.
	Enable()
	// Enabled returns true if this field currently enabled.
	Enabled() bool
	// Disable this field. Disabled fields will not be focused, will ignore most updates and will be excluded from views.
	Disable()

	// Focus this field so it can process update messages. Only one field per form should ever be focused.
	Focus()
	// Focused returns true if this field is processing updates.
	Focused() bool
	// Blur removes focus so this field stops processing update messages.
	Blur()

	// Show ensures an enabled field will be visible in a view.
	Show()
	// Hidden returns true if this field should not appear in a view.
	Hidden() bool
	// Hide ensures that this field will not be visible in a view.
	Hide()

	// View renders this field.
	View() string

	// Validate returns a command to check the current state of the field. The command MUST produce a `ValidationMsg`.
	Validate() tea.Cmd
}

Field represents an individual form field in a linear sequence of inputs. Initially disabled and hidden, fields should be enabled programmatically (either during initialization or in response to events related to the field); it is not necessary to show fields as they will be shown as the form progresses.

type Fields

type Fields []Field

Fields is a list of fields that make up a form. When constructing a form, be sure to use pointers to the individual field structs at the time of the update. Most Bubble Tea updates operate on values, not references, so this is a little different.

func (Fields) Enabled

func (f Fields) Enabled() bool

Enabled returns true if at least one field in the form is enabled.

func (Fields) Focused

func (f Fields) Focused() bool

Focused returns true if at least one field in the form has focus.

func (Fields) Init

func (f Fields) Init() tea.Cmd

Init returns a command to invoke in response to a form started message.

func (Fields) Update

func (f Fields) Update(msg tea.Msg) tea.Cmd

Update manages the transition when individual fields are submitted. IMPORTANT: the message cannot be delivered to the individual fields, they must still be updated (presumably after the form itself has had a chance to update).

func (Fields) View

func (f Fields) View() string

View returns the views of all enabled, non-hidden fields (each with a trailing newline).

type File

type File struct {
	Required    string
	Missing     string
	Directory   string
	RegularFile string
}

func (*File) ValidateTextField

func (v *File) ValidateTextField(value string) tea.Msg

type FileCompletions

type FileCompletions struct {
	// Working directory for relative completions.
	WorkingDirectory string
	// Flag indicating "." files can be shown.
	AllowHidden bool
	// Required extensions, empty means directories only, `[]string{"*"}` is all files.
	Extensions []string
}

func (*FileCompletions) Suggest

func (c *FileCompletions) Suggest(path string) []string

Suggest returns directory contents matching the base name of the supplied path.

func (*FileCompletions) ToggleHidden

func (c *FileCompletions) ToggleHidden()

ToggleHidden flips the allow hidden state.

func (*FileCompletions) View

func (c *FileCompletions) View(suggestion string) string

View returns the base name of the supplied suggestion.

type FinishedMsg

type FinishedMsg struct{}

FinishedMsg indicates that the last field on the form has been submitted.

type MultiChoiceField

type MultiChoiceField struct {
	multichoiceinput.Model

	Validator MultiChoiceFieldValidator
	// contains filtered or unexported fields
}

func NewMultiChoiceField

func NewMultiChoiceField() MultiChoiceField

func (*MultiChoiceField) Disable

func (m *MultiChoiceField) Disable()

func (*MultiChoiceField) Enable

func (m *MultiChoiceField) Enable()

func (MultiChoiceField) Enabled

func (m MultiChoiceField) Enabled() bool

func (MultiChoiceField) Hidden

func (m MultiChoiceField) Hidden() bool

func (*MultiChoiceField) Hide

func (m *MultiChoiceField) Hide()

func (*MultiChoiceField) SetEnabled

func (m *MultiChoiceField) SetEnabled(enabled bool)

func (*MultiChoiceField) SetHidden

func (m *MultiChoiceField) SetHidden(hidden bool)

func (*MultiChoiceField) Show

func (m *MultiChoiceField) Show()

func (MultiChoiceField) Update

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

func (MultiChoiceField) Validate

func (m MultiChoiceField) Validate() tea.Cmd

func (MultiChoiceField) View

func (m MultiChoiceField) View() string

type MultiChoiceFieldValidator

type MultiChoiceFieldValidator interface {
	ValidateMultiChoiceField(values []string) tea.Msg
}

type Required

type Required struct {
	Error       string
	IgnoreSpace bool
}

func (*Required) ValidateChoiceField

func (r *Required) ValidateChoiceField(value string) tea.Msg

func (*Required) ValidateMultiChoiceField

func (r *Required) ValidateMultiChoiceField(values []string) tea.Msg

func (*Required) ValidateTextField

func (r *Required) ValidateTextField(value string) tea.Msg

type StaticCompletions

type StaticCompletions []string

StaticCompletions is just a static list of allowed final values for a field.

func (StaticCompletions) Suggest

func (s StaticCompletions) Suggest(prefix string) []string

Suggest returns the values matching the supplied prefix.

func (StaticCompletions) View

func (s StaticCompletions) View(suggestion string) string

View returns the suggestion unmodified.

type SuggestionMsg

type SuggestionMsg string

SuggestionMsg should be used to update the value of the corresponding model.

type TextField

type TextField struct {
	textinput.Model

	CompletionModel
	Validator TextFieldValidator
	// contains filtered or unexported fields
}

func NewTextField

func NewTextField() TextField

func (*TextField) Disable

func (m *TextField) Disable()

func (*TextField) Enable

func (m *TextField) Enable()

func (TextField) Enabled

func (m TextField) Enabled() bool

func (TextField) Hidden

func (m TextField) Hidden() bool

func (*TextField) Hide

func (m *TextField) Hide()

func (*TextField) SetEnabled

func (m *TextField) SetEnabled(enabled bool)

func (*TextField) SetHidden

func (m *TextField) SetHidden(hidden bool)

func (*TextField) Show

func (m *TextField) Show()

func (TextField) Update

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

func (TextField) Validate

func (m TextField) Validate() tea.Cmd

func (TextField) View

func (m TextField) View() string

type TextFieldValidator

type TextFieldValidator interface {
	ValidateTextField(value string) tea.Msg
}

type URL

type URL struct {
	Required   string
	InvalidURL string
	Absolute   string
}

func (*URL) ValidateTextField

func (v *URL) ValidateTextField(value string) tea.Msg

type ValidationMsg

type ValidationMsg string

ValidationMsg is used to asynchronously validate form fields. An empty string is used to indicate a valid field while any non-empty strings indicates an error with the current field value. Validation messages are typically rendered in the view of a field and will be cleared on the first key press after the validation occurs.

Jump to

Keyboard shortcuts

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