Documentation ¶
Index ¶
- Variables
- func NextField() tea.Msg
- func PrevField() tea.Msg
- func Run(field Field) error
- func ValidateLength(min, max int) func(s string) error
- func ValidateMaxLength(max int) func(s string) error
- func ValidateMinLength(min int) func(s string) error
- func ValidateNotEmpty() func(s string) error
- func ValidateOneOf(options ...string) func(string) error
- type Accessor
- type Confirm
- func (c *Confirm) Accessor(accessor Accessor[bool]) *Confirm
- func (c *Confirm) Affirmative(affirmative string) *Confirm
- func (c *Confirm) Blur() tea.Cmd
- func (c *Confirm) Description(description string) *Confirm
- func (c *Confirm) DescriptionFunc(f func() string, bindings any) *Confirm
- func (c *Confirm) Error() error
- func (c *Confirm) Focus() tea.Cmd
- func (c *Confirm) GetKey() string
- func (c *Confirm) GetValue() any
- func (c *Confirm) Init() tea.Cmd
- func (c *Confirm) Inline(inline bool) *Confirm
- func (c *Confirm) Key(key string) *Confirm
- func (c *Confirm) KeyBinds() []key.Binding
- func (c *Confirm) Negative(negative string) *Confirm
- func (c *Confirm) Run() error
- func (*Confirm) Skip() bool
- func (c *Confirm) String() string
- func (c *Confirm) Title(title string) *Confirm
- func (c *Confirm) TitleFunc(f func() string, bindings any) *Confirm
- func (c *Confirm) Update(msg tea.Msg) (tea.Model, tea.Cmd)
- func (c *Confirm) Validate(validate func(bool) error) *Confirm
- func (c *Confirm) Value(value *bool) *Confirm
- func (c *Confirm) View() string
- func (c *Confirm) WithAccessible(accessible bool) Field
- func (c *Confirm) WithHeight(height int) Field
- func (c *Confirm) WithKeyMap(k *KeyMap) Field
- func (c *Confirm) WithPosition(p FieldPosition) Field
- func (c *Confirm) WithTheme(theme *Theme) Field
- func (c *Confirm) WithWidth(width int) Field
- func (*Confirm) Zoom() bool
- type ConfirmKeyMap
- type EchoMode
- type EmbeddedAccessor
- type Eval
- type Field
- type FieldPosition
- type FieldStyles
- type FilePicker
- func (f *FilePicker) Accessor(accessor Accessor[string]) *FilePicker
- func (f *FilePicker) AllowedTypes(types []string) *FilePicker
- func (f *FilePicker) Blur() tea.Cmd
- func (f *FilePicker) CurrentDirectory(directory string) *FilePicker
- func (f *FilePicker) Description(description string) *FilePicker
- func (f *FilePicker) DirAllowed(v bool) *FilePicker
- func (f *FilePicker) Error() error
- func (f *FilePicker) FileAllowed(v bool) *FilePicker
- func (f *FilePicker) Focus() tea.Cmd
- func (f *FilePicker) GetKey() string
- func (f *FilePicker) GetValue() any
- func (f *FilePicker) Height(height int) *FilePicker
- func (f *FilePicker) Init() tea.Cmd
- func (f *FilePicker) Key(key string) *FilePicker
- func (f *FilePicker) KeyBinds() []key.Binding
- func (f *FilePicker) Picking(v bool) *FilePicker
- func (f *FilePicker) Run() error
- func (f *FilePicker) ShowHidden(v bool) *FilePicker
- func (f *FilePicker) ShowPermissions(v bool) *FilePicker
- func (f *FilePicker) ShowSize(v bool) *FilePicker
- func (*FilePicker) Skip() bool
- func (f *FilePicker) Title(title string) *FilePicker
- func (f *FilePicker) Update(msg tea.Msg) (tea.Model, tea.Cmd)
- func (f *FilePicker) Validate(validate func(string) error) *FilePicker
- func (f *FilePicker) Value(value *string) *FilePicker
- func (f *FilePicker) View() string
- func (f *FilePicker) WithAccessible(accessible bool) Field
- func (f *FilePicker) WithHeight(height int) Field
- func (f *FilePicker) WithKeyMap(k *KeyMap) Field
- func (f *FilePicker) WithPosition(p FieldPosition) Field
- func (f *FilePicker) WithTheme(theme *Theme) Field
- func (f *FilePicker) WithWidth(width int) Field
- func (f *FilePicker) Zoom() bool
- type FilePickerKeyMap
- type Form
- func (f *Form) Errors() []error
- func (f *Form) Get(key string) any
- func (f *Form) GetBool(key string) bool
- func (f *Form) GetInt(key string) int
- func (f *Form) GetString(key string) string
- func (f *Form) Help() help.Model
- func (f *Form) Init() tea.Cmd
- func (f *Form) KeyBinds() []key.Binding
- func (f *Form) NextField() tea.Cmd
- func (f *Form) NextGroup() tea.Cmd
- func (f *Form) PrevField() tea.Cmd
- func (f *Form) PrevGroup() tea.Cmd
- func (f *Form) Run() error
- func (f *Form) RunWithContext(ctx context.Context) error
- func (f *Form) Update(msg tea.Msg) (tea.Model, tea.Cmd)
- func (f *Form) UpdateFieldPositions() *Form
- func (f *Form) View() string
- func (f *Form) WithAccessible(accessible bool) *Form
- func (f *Form) WithHeight(height int) *Form
- func (f *Form) WithInput(r io.Reader) *Form
- func (f *Form) WithKeyMap(keymap *KeyMap) *Form
- func (f *Form) WithLayout(layout Layout) *Form
- func (f *Form) WithOutput(w io.Writer) *Form
- func (f *Form) WithProgramOptions(opts ...tea.ProgramOption) *Form
- func (f *Form) WithShowErrors(v bool) *Form
- func (f *Form) WithShowHelp(v bool) *Form
- func (f *Form) WithTheme(theme *Theme) *Form
- func (f *Form) WithTimeout(t time.Duration) *Form
- func (f *Form) WithWidth(width int) *Form
- type FormState
- type Group
- func (g *Group) Content() string
- func (g *Group) Description(description string) *Group
- func (g *Group) Errors() []error
- func (g *Group) Footer() string
- func (g *Group) Init() tea.Cmd
- func (g *Group) Title(title string) *Group
- func (g *Group) Update(msg tea.Msg) (tea.Model, tea.Cmd)
- func (g *Group) View() string
- func (g *Group) WithHeight(height int) *Group
- func (g *Group) WithHide(hide bool) *Group
- func (g *Group) WithHideFunc(hideFunc func() bool) *Group
- func (g *Group) WithKeyMap(k *KeyMap) *Group
- func (g *Group) WithShowErrors(show bool) *Group
- func (g *Group) WithShowHelp(show bool) *Group
- func (g *Group) WithTheme(t *Theme) *Group
- func (g *Group) WithWidth(width int) *Group
- type Input
- func (i *Input) Accessor(accessor Accessor[string]) *Input
- func (i *Input) Blur() tea.Cmd
- func (i *Input) CharLimit(charlimit int) *Input
- func (i *Input) Description(description string) *Input
- func (i *Input) DescriptionFunc(f func() string, bindings any) *Input
- func (i *Input) EchoMode(mode EchoMode) *Input
- func (i *Input) Error() error
- func (i *Input) Focus() tea.Cmd
- func (i *Input) GetKey() string
- func (i *Input) GetValue() any
- func (i *Input) Init() tea.Cmd
- func (i *Input) Inline(inline bool) *Input
- func (i *Input) Key(key string) *Input
- func (i *Input) KeyBinds() []key.Binding
- func (i *Input) Password(password bool) *Inputdeprecated
- func (i *Input) Placeholder(str string) *Input
- func (i *Input) PlaceholderFunc(f func() string, bindings any) *Input
- func (i *Input) Prompt(prompt string) *Input
- func (i *Input) Run() error
- func (*Input) Skip() bool
- func (i *Input) Suggestions(suggestions []string) *Input
- func (i *Input) SuggestionsFunc(f func() []string, bindings any) *Input
- func (i *Input) Title(title string) *Input
- func (i *Input) TitleFunc(f func() string, bindings any) *Input
- func (i *Input) Update(msg tea.Msg) (tea.Model, tea.Cmd)
- func (i *Input) Validate(validate func(string) error) *Input
- func (i *Input) Value(value *string) *Input
- func (i *Input) View() string
- func (i *Input) WithAccessible(accessible bool) Field
- func (i *Input) WithHeight(height int) Field
- func (i *Input) WithKeyMap(k *KeyMap) Field
- func (i *Input) WithPosition(p FieldPosition) Field
- func (i *Input) WithTheme(theme *Theme) Field
- func (i *Input) WithWidth(width int) Field
- func (*Input) Zoom() bool
- type InputKeyMap
- type KeyMap
- type Layout
- type MultiSelect
- func (m *MultiSelect[T]) Accessor(accessor Accessor[[]T]) *MultiSelect[T]
- func (m *MultiSelect[T]) Blur() tea.Cmd
- func (m *MultiSelect[T]) Description(description string) *MultiSelect[T]
- func (m *MultiSelect[T]) DescriptionFunc(f func() string, bindings any) *MultiSelect[T]
- func (m *MultiSelect[T]) Error() error
- func (m *MultiSelect[T]) Filterable(filterable bool) *MultiSelect[T]
- func (m *MultiSelect[T]) Filtering(filtering bool) *MultiSelect[T]
- func (m *MultiSelect[T]) Focus() tea.Cmd
- func (m *MultiSelect[T]) GetKey() string
- func (m *MultiSelect[T]) GetValue() any
- func (m *MultiSelect[T]) Height(height int) *MultiSelect[T]
- func (m *MultiSelect[T]) Init() tea.Cmd
- func (m *MultiSelect[T]) Key(key string) *MultiSelect[T]
- func (m *MultiSelect[T]) KeyBinds() []key.Binding
- func (m *MultiSelect[T]) Limit(limit int) *MultiSelect[T]
- func (m *MultiSelect[T]) Options(options ...Option[T]) *MultiSelect[T]
- func (m *MultiSelect[T]) OptionsFunc(f func() []Option[T], bindings any) *MultiSelect[T]
- func (m *MultiSelect[T]) Run() error
- func (*MultiSelect[T]) Skip() bool
- func (m *MultiSelect[T]) Title(title string) *MultiSelect[T]
- func (m *MultiSelect[T]) TitleFunc(f func() string, bindings any) *MultiSelect[T]
- func (m *MultiSelect[T]) Update(msg tea.Msg) (tea.Model, tea.Cmd)
- func (m *MultiSelect[T]) Validate(validate func([]T) error) *MultiSelect[T]
- func (m *MultiSelect[T]) Value(value *[]T) *MultiSelect[T]
- func (m *MultiSelect[T]) View() string
- func (m *MultiSelect[T]) WithAccessible(accessible bool) Field
- func (m *MultiSelect[T]) WithHeight(height int) Field
- func (m *MultiSelect[T]) WithKeyMap(k *KeyMap) Field
- func (m *MultiSelect[T]) WithPosition(p FieldPosition) Field
- func (m *MultiSelect[T]) WithTheme(theme *Theme) Field
- func (m *MultiSelect[T]) WithWidth(width int) Field
- func (*MultiSelect[T]) Zoom() bool
- type MultiSelectKeyMap
- type Note
- func (n *Note) Blur() tea.Cmd
- func (n *Note) Description(description string) *Note
- func (n *Note) DescriptionFunc(f func() string, bindings any) *Note
- func (n *Note) Error() error
- func (n *Note) Focus() tea.Cmd
- func (n *Note) GetKey() string
- func (n *Note) GetValue() any
- func (n *Note) Height(height int) *Note
- func (n *Note) Init() tea.Cmd
- func (n *Note) KeyBinds() []key.Binding
- func (n *Note) Next(show bool) *Note
- func (n *Note) NextLabel(label string) *Note
- func (n *Note) Run() error
- func (n *Note) Skip() bool
- func (n *Note) Title(title string) *Note
- func (n *Note) TitleFunc(f func() string, bindings any) *Note
- func (n *Note) Update(msg tea.Msg) (tea.Model, tea.Cmd)
- func (n *Note) View() string
- func (n *Note) WithAccessible(accessible bool) Field
- func (n *Note) WithHeight(height int) Field
- func (n *Note) WithKeyMap(k *KeyMap) Field
- func (n *Note) WithPosition(p FieldPosition) Field
- func (n *Note) WithTheme(theme *Theme) Field
- func (n *Note) WithWidth(width int) Field
- func (n *Note) Zoom() bool
- type NoteKeyMap
- type Option
- type PointerAccessor
- type Select
- func (s *Select[T]) Accessor(accessor Accessor[T]) *Select[T]
- func (s *Select[T]) Blur() tea.Cmd
- func (s *Select[T]) Description(description string) *Select[T]
- func (s *Select[T]) DescriptionFunc(f func() string, bindings any) *Select[T]
- func (s *Select[T]) Error() error
- func (s *Select[T]) Filtering(filtering bool) *Select[T]
- func (s *Select[T]) Focus() tea.Cmd
- func (s *Select[T]) GetKey() string
- func (s *Select[T]) GetValue() any
- func (s *Select[T]) Height(height int) *Select[T]
- func (s *Select[T]) Init() tea.Cmd
- func (s *Select[T]) Inline(v bool) *Select[T]
- func (s *Select[T]) Key(key string) *Select[T]
- func (s *Select[T]) KeyBinds() []key.Binding
- func (s *Select[T]) Options(options ...Option[T]) *Select[T]
- func (s *Select[T]) OptionsFunc(f func() []Option[T], bindings any) *Select[T]
- func (s *Select[T]) Run() error
- func (*Select[T]) Skip() bool
- func (s *Select[T]) Title(title string) *Select[T]
- func (s *Select[T]) TitleFunc(f func() string, bindings any) *Select[T]
- func (s *Select[T]) Update(msg tea.Msg) (tea.Model, tea.Cmd)
- func (s *Select[T]) Validate(validate func(T) error) *Select[T]
- func (s *Select[T]) Value(value *T) *Select[T]
- func (s *Select[T]) View() string
- func (s *Select[T]) WithAccessible(accessible bool) Field
- func (s *Select[T]) WithHeight(height int) Field
- func (s *Select[T]) WithKeyMap(k *KeyMap) Field
- func (s *Select[T]) WithPosition(p FieldPosition) Field
- func (s *Select[T]) WithTheme(theme *Theme) Field
- func (s *Select[T]) WithWidth(width int) Field
- func (*Select[T]) Zoom() bool
- type SelectKeyMap
- type Text
- func (t *Text) Accessor(accessor Accessor[string]) *Text
- func (t *Text) Blur() tea.Cmd
- func (t *Text) CharLimit(charlimit int) *Text
- func (t *Text) Description(description string) *Text
- func (t *Text) DescriptionFunc(f func() string, bindings any) *Text
- func (t *Text) Editor(editor ...string) *Text
- func (t *Text) EditorExtension(extension string) *Text
- func (t *Text) Error() error
- func (t *Text) Focus() tea.Cmd
- func (t *Text) GetKey() string
- func (t *Text) GetValue() any
- func (t *Text) Init() tea.Cmd
- func (t *Text) Key(key string) *Text
- func (t *Text) KeyBinds() []key.Binding
- func (t *Text) Lines(lines int) *Text
- func (t *Text) Placeholder(str string) *Text
- func (t *Text) PlaceholderFunc(f func() string, bindings any) *Text
- func (t *Text) Run() error
- func (t *Text) ShowLineNumbers(show bool) *Text
- func (*Text) Skip() bool
- func (t *Text) Title(title string) *Text
- func (t *Text) TitleFunc(f func() string, bindings any) *Text
- func (t *Text) Update(msg tea.Msg) (tea.Model, tea.Cmd)
- func (t *Text) Validate(validate func(string) error) *Text
- func (t *Text) Value(value *string) *Text
- func (t *Text) View() string
- func (t *Text) WithAccessible(accessible bool) Field
- func (t *Text) WithHeight(height int) Field
- func (t *Text) WithKeyMap(k *KeyMap) Field
- func (t *Text) WithPosition(p FieldPosition) Field
- func (t *Text) WithTheme(theme *Theme) Field
- func (t *Text) WithWidth(width int) Field
- func (*Text) Zoom() bool
- type TextInputStyles
- type TextKeyMap
- type Theme
Constants ¶
This section is empty.
Variables ¶
var ErrTimeout = errors.New("timeout")
ErrTimeout is the error returned when the timeout is reached.
var ErrTimeoutUnsupported = errors.New("timeout is not supported in accessible mode")
ErrTimeoutUnsupported is the error returned when timeout is used while in accessible mode.
var ErrUserAborted = errors.New("user aborted")
ErrUserAborted is the error returned when a user exits the form before submitting.
Functions ¶
func ValidateLength ¶
ValidateLength checks if the length of the input is within the specified range.
func ValidateMaxLength ¶
ValidateMaxLength checks if the length of the input is at most max.
func ValidateMinLength ¶
ValidateMinLength checks if the length of the input is at least min.
func ValidateNotEmpty ¶
ValidateNotEmpty checks if the input is not empty.
func ValidateOneOf ¶
ValidateOneOf checks if a string is one of the specified options.
Types ¶
type Accessor ¶
type Accessor[T any] interface { Get() T Set(value T) }
Accessor give read/write access to field values.
type Confirm ¶
type Confirm struct {
// contains filtered or unexported fields
}
Confirm is a form confirm field.
func (*Confirm) Affirmative ¶
Affirmative sets the affirmative value of the confirm field.
func (*Confirm) Description ¶
Description sets the description of the confirm field.
func (*Confirm) DescriptionFunc ¶
DescriptionFunc sets the description function of the confirm field.
func (*Confirm) WithAccessible ¶
WithAccessible sets the accessible mode of the confirm field.
func (*Confirm) WithHeight ¶
WithHeight sets the height of the confirm field.
func (*Confirm) WithKeyMap ¶
WithKeyMap sets the keymap of the confirm field.
func (*Confirm) WithPosition ¶
func (c *Confirm) WithPosition(p FieldPosition) Field
WithPosition sets the position of the confirm field.
type ConfirmKeyMap ¶
type ConfirmKeyMap struct { Next key.Binding Prev key.Binding Toggle key.Binding Submit key.Binding Accept key.Binding Reject key.Binding }
ConfirmKeyMap is the keybindings for confirm fields.
type EchoMode ¶
EchoMode sets the input behavior of the text Input field.
const ( // EchoNormal displays text as is. // This is the default behavior. EchoModeNormal EchoMode = EchoMode(textinput.EchoNormal) // EchoPassword displays the EchoCharacter mask instead of actual characters. // This is commonly used for password fields. EchoModePassword EchoMode = EchoMode(textinput.EchoPassword) // EchoNone displays nothing as characters are entered. // This is commonly seen for password fields on the command line. EchoModeNone EchoMode = EchoMode(textinput.EchoNone) )
type EmbeddedAccessor ¶
type EmbeddedAccessor[T any] struct { // contains filtered or unexported fields }
EmbeddedAccessor is a basic accessor, acting as the default one for fields.
type Eval ¶
type Eval[T any] struct { // contains filtered or unexported fields }
Eval is an evaluatable value, it stores a cached value and a function to recompute it. It's bindings are what we check to see if we need to recompute the value.
By default it is also cached.
type Field ¶
type Field interface { // Bubble Tea Model Init() tea.Cmd Update(tea.Msg) (tea.Model, tea.Cmd) View() string // Bubble Tea Events Blur() tea.Cmd Focus() tea.Cmd // Errors and Validation Error() error // Run runs the field individually. Run() error // Skip returns whether this input should be skipped or not. Skip() bool // Zoom returns whether this input should be zoomed or not. // Zoom allows the field to take focus of the group / form height. Zoom() bool // KeyBinds returns help keybindings. KeyBinds() []key.Binding // WithTheme sets the theme on a field. WithTheme(*Theme) Field // WithAccessible sets whether the field should run in accessible mode. WithAccessible(bool) Field // WithKeyMap sets the keymap on a field. WithKeyMap(*KeyMap) Field // WithWidth sets the width of a field. WithWidth(int) Field // WithHeight sets the height of a field. WithHeight(int) Field // WithPosition tells the field the index of the group and position it is in. WithPosition(FieldPosition) Field // GetKey returns the field's key. GetKey() string // GetValue returns the field's value. GetValue() any }
Field is a primitive of a form.
A field represents a single input control on a form such as a text input, confirm button, select option, etc...
Each field implements the Bubble Tea Model interface.
type FieldPosition ¶
type FieldPosition struct { Group int Field int FirstField int LastField int GroupCount int FirstGroup int LastGroup int }
FieldPosition is positional information about the given field and form.
func (FieldPosition) IsFirst ¶
func (p FieldPosition) IsFirst() bool
IsFirst returns whether a field is the form's first field.
func (FieldPosition) IsLast ¶
func (p FieldPosition) IsLast() bool
IsLast returns whether a field is the form's last field.
type FieldStyles ¶
type FieldStyles struct { Base lipgloss.Style Title lipgloss.Style Description lipgloss.Style ErrorIndicator lipgloss.Style ErrorMessage lipgloss.Style // Select styles. SelectSelector lipgloss.Style // Selection indicator Option lipgloss.Style // Select options NextIndicator lipgloss.Style PrevIndicator lipgloss.Style // FilePicker styles. Directory lipgloss.Style File lipgloss.Style // Multi-select styles. MultiSelectSelector lipgloss.Style SelectedOption lipgloss.Style SelectedPrefix lipgloss.Style UnselectedOption lipgloss.Style UnselectedPrefix lipgloss.Style // Textinput and teatarea styles. TextInput TextInputStyles // Confirm styles. FocusedButton lipgloss.Style BlurredButton lipgloss.Style // Card styles. Card lipgloss.Style NoteTitle lipgloss.Style Next lipgloss.Style }
FieldStyles are the styles for input fields.
type FilePicker ¶
type FilePicker struct {
// contains filtered or unexported fields
}
FilePicker is a form file file field.
func (*FilePicker) Accessor ¶
func (f *FilePicker) Accessor(accessor Accessor[string]) *FilePicker
Accessor sets the accessor of the file field.
func (*FilePicker) AllowedTypes ¶
func (f *FilePicker) AllowedTypes(types []string) *FilePicker
AllowedTypes sets the allowed types of the file field. These will be the only valid file types accepted, other files will show as disabled.
func (*FilePicker) CurrentDirectory ¶
func (f *FilePicker) CurrentDirectory(directory string) *FilePicker
CurrentDirectory sets the directory of the file field.
func (*FilePicker) Description ¶
func (f *FilePicker) Description(description string) *FilePicker
Description sets the description of the file field.
func (*FilePicker) DirAllowed ¶
func (f *FilePicker) DirAllowed(v bool) *FilePicker
DirAllowed sets whether to allow files to be selected.
func (*FilePicker) Error ¶
func (f *FilePicker) Error() error
Error returns the error of the file field.
func (*FilePicker) FileAllowed ¶
func (f *FilePicker) FileAllowed(v bool) *FilePicker
FileAllowed sets whether to allow files to be selected.
func (*FilePicker) GetKey ¶
func (f *FilePicker) GetKey() string
GetKey returns the key of the field.
func (*FilePicker) GetValue ¶
func (f *FilePicker) GetValue() any
GetValue returns the value of the field.
func (*FilePicker) Height ¶
func (f *FilePicker) Height(height int) *FilePicker
Height sets the height of the file field. If the number of options exceeds the height, the file field will become scrollable.
func (*FilePicker) Key ¶
func (f *FilePicker) Key(key string) *FilePicker
Key sets the key of the file field which can be used to retrieve the value after submission.
func (*FilePicker) KeyBinds ¶
func (f *FilePicker) KeyBinds() []key.Binding
KeyBinds returns the help keybindings for the file field.
func (*FilePicker) Picking ¶
func (f *FilePicker) Picking(v bool) *FilePicker
Picking sets whether the file picker should be in the picking files state.
func (*FilePicker) ShowHidden ¶
func (f *FilePicker) ShowHidden(v bool) *FilePicker
ShowHidden sets whether to show hidden files.
func (*FilePicker) ShowPermissions ¶
func (f *FilePicker) ShowPermissions(v bool) *FilePicker
ShowPermissions sets whether to show file permissions.
func (*FilePicker) ShowSize ¶
func (f *FilePicker) ShowSize(v bool) *FilePicker
ShowSize sets whether to show file sizes.
func (*FilePicker) Skip ¶
func (*FilePicker) Skip() bool
Skip returns whether the file should be skipped or should be blocking.
func (*FilePicker) Title ¶
func (f *FilePicker) Title(title string) *FilePicker
Title sets the title of the file field.
func (*FilePicker) Validate ¶
func (f *FilePicker) Validate(validate func(string) error) *FilePicker
Validate sets the validation function of the file field.
func (*FilePicker) Value ¶
func (f *FilePicker) Value(value *string) *FilePicker
Value sets the value of the file field.
func (*FilePicker) WithAccessible ¶
func (f *FilePicker) WithAccessible(accessible bool) Field
WithAccessible sets the accessible mode of the file field.
func (*FilePicker) WithHeight ¶
func (f *FilePicker) WithHeight(height int) Field
WithHeight sets the height of the file field.
func (*FilePicker) WithKeyMap ¶
func (f *FilePicker) WithKeyMap(k *KeyMap) Field
WithKeyMap sets the keymap on a file field.
func (*FilePicker) WithPosition ¶
func (f *FilePicker) WithPosition(p FieldPosition) Field
WithPosition sets the position of the file field.
func (*FilePicker) WithTheme ¶
func (f *FilePicker) WithTheme(theme *Theme) Field
WithTheme sets the theme of the file field.
func (*FilePicker) WithWidth ¶
func (f *FilePicker) WithWidth(width int) Field
WithWidth sets the width of the file field.
func (*FilePicker) Zoom ¶
func (f *FilePicker) Zoom() bool
Zoom returns whether the input should be zoomed.
type FilePickerKeyMap ¶
type FilePickerKeyMap struct { Open key.Binding Close key.Binding GoToTop key.Binding GoToLast key.Binding PageUp key.Binding PageDown key.Binding Back key.Binding Select key.Binding Up key.Binding Down key.Binding Prev key.Binding Next key.Binding Submit key.Binding }
FilePickerKey is the keybindings for filepicker fields.
type Form ¶
type Form struct { // callbacks SubmitCmd tea.Cmd CancelCmd tea.Cmd State FormState // contains filtered or unexported fields }
Form is a collection of groups that are displayed one at a time on a "page".
The form can navigate between groups and is complete once all the groups are complete.
func NewForm ¶
NewForm returns a form with the given groups and default themes and keybindings.
Use With* methods to customize the form with options, such as setting different themes and keybindings.
func (*Form) RunWithContext ¶
RunWithContext runs the form with the given context.
func (*Form) UpdateFieldPositions ¶
UpdateFieldPositions sets the position on all the fields.
func (*Form) WithAccessible ¶
WithAccessible sets the form to run in accessible mode to avoid redrawing the views which makes it easier for screen readers to read and describe the form.
This avoids using the Bubble Tea renderer and instead simply uses basic terminal prompting to gather input which degrades the user experience but provides accessibility.
func (*Form) WithHeight ¶
WithHeight sets the height of a form.
func (*Form) WithKeyMap ¶
WithKeyMap sets the keymap on a form.
This allows customization of the form key bindings.
func (*Form) WithLayout ¶
WithLayout sets the layout on a form.
This allows customization of the form group layout.
func (*Form) WithOutput ¶
WithOutput sets the io.Writer to output the form.
func (*Form) WithProgramOptions ¶
func (f *Form) WithProgramOptions(opts ...tea.ProgramOption) *Form
WithProgramOptions sets the tea options of the form.
func (*Form) WithShowErrors ¶
WithShowErrors sets whether or not the form should show errors.
This allows the form groups and fields to show errors when the Validate function returns an error.
func (*Form) WithShowHelp ¶
WithShowHelp sets whether or not the form should show help.
This allows the form groups and field to show what keybindings are available to the user.
func (*Form) WithTheme ¶
WithTheme sets the theme on a form.
This allows all groups and fields to be themed consistently, however themes can be applied to each group and field individually for more granular control.
func (*Form) WithTimeout ¶
WithTimeout sets the duration for the form to be killed.
type Group ¶
type Group struct {
// contains filtered or unexported fields
}
Group is a collection of fields that are displayed together with a page of the form. While a group is displayed the form completer can switch between fields in the group.
If any of the fields in a group have errors, the form will not be able to progress to the next group.
func (*Group) Description ¶
Description sets the group's description.
func (*Group) WithHeight ¶
WithHeight sets the height on a group.
func (*Group) WithHideFunc ¶
WithHideFunc sets the function that checks if this group should be skipped.
func (*Group) WithKeyMap ¶
WithKeyMap sets the keymap on a group.
func (*Group) WithShowErrors ¶
WithShowErrors sets whether or not the group's errors should be shown.
func (*Group) WithShowHelp ¶
WithShowHelp sets whether or not the group's help should be shown.
type Input ¶
type Input struct {
// contains filtered or unexported fields
}
Input is a input field.
The input field is a field that allows the user to enter text. Use it to user input. It can be used for collecting text, passwords, or other short input.
The input field supports Suggestions, Placeholder, and Validation.
func NewInput ¶
func NewInput() *Input
NewInput creates a new input field.
The input field is a field that allows the user to enter text. Use it to user input. It can be used for collecting text, passwords, or other short input.
The input field supports Suggestions, Placeholder, and Validation.
func (*Input) Description ¶
Description sets the description of the input field.
The Description is static for dynamic Description use `DescriptionFunc`.
func (*Input) DescriptionFunc ¶
DescriptionFunc sets the description func of the input field.
The DescriptionFunc will be re-evaluated when the binding of the DescriptionFunc changes. This is useful when you want to display dynamic content and update the description when another part of your form changes.
See README#Dynamic for more usage information.
func (*Input) Placeholder ¶
Placeholder sets the placeholder of the text input.
func (*Input) PlaceholderFunc ¶
PlaceholderFunc sets the placeholder func of the text input.
func (*Input) Suggestions ¶
Suggestions sets the suggestions to display for autocomplete in the input field.
The suggestions are static for dynamic suggestions use `SuggestionsFunc`.
func (*Input) SuggestionsFunc ¶
SuggestionsFunc sets the suggestions func to display for autocomplete in the input field.
The SuggestionsFunc will be re-evaluated when the binding of the SuggestionsFunc changes. This is useful when you want to display dynamic suggestions when another part of your form changes.
See README#Dynamic for more usage information.
func (*Input) Title ¶
Title sets the title of the input field.
The Title is static for dynamic Title use `TitleFunc`.
func (*Input) TitleFunc ¶
TitleFunc sets the title func of the input field.
The TitleFunc will be re-evaluated when the binding of the TitleFunc changes. This is useful when you want to display dynamic content and update the title when another part of your form changes.
See README#Dynamic for more usage information.
func (*Input) WithAccessible ¶
WithAccessible sets the accessible mode of the input field.
func (*Input) WithHeight ¶
WithHeight sets the height of the input field.
func (*Input) WithKeyMap ¶
WithKeyMap sets the keymap on an input field.
func (*Input) WithPosition ¶
func (i *Input) WithPosition(p FieldPosition) Field
WithPosition sets the position of the input field.
type InputKeyMap ¶
type InputKeyMap struct { AcceptSuggestion key.Binding Next key.Binding Prev key.Binding Submit key.Binding }
InputKeyMap is the keybindings for input fields.
type KeyMap ¶
type KeyMap struct { Quit key.Binding Confirm ConfirmKeyMap FilePicker FilePickerKeyMap Input InputKeyMap MultiSelect MultiSelectKeyMap Note NoteKeyMap Select SelectKeyMap Text TextKeyMap }
KeyMap is the keybindings to navigate the form.
func NewDefaultKeyMap ¶
func NewDefaultKeyMap() *KeyMap
NewDefaultKeyMap returns a new default keymap.
type Layout ¶
A Layout is responsible for laying out groups in a form.
var LayoutDefault Layout = &layoutDefault{}
Default layout shows a single group at a time.
var LayoutStack Layout = &layoutStack{}
Stack layout stacks all groups on top of each other.
func LayoutColumns ¶
Column layout distributes groups in even columns.
func LayoutGrid ¶
Grid layout distributes groups in a grid.
type MultiSelect ¶
type MultiSelect[T comparable] struct { // contains filtered or unexported fields }
MultiSelect is a form multi-select field.
func NewMultiSelect ¶
func NewMultiSelect[T comparable]() *MultiSelect[T]
NewMultiSelect returns a new multi-select field.
func (*MultiSelect[T]) Accessor ¶
func (m *MultiSelect[T]) Accessor(accessor Accessor[[]T]) *MultiSelect[T]
Accessor sets the accessor of the input field.
func (*MultiSelect[T]) Blur ¶
func (m *MultiSelect[T]) Blur() tea.Cmd
Blur blurs the multi-select field.
func (*MultiSelect[T]) Description ¶
func (m *MultiSelect[T]) Description(description string) *MultiSelect[T]
Description sets the description of the multi-select field.
func (*MultiSelect[T]) DescriptionFunc ¶
func (m *MultiSelect[T]) DescriptionFunc(f func() string, bindings any) *MultiSelect[T]
DescriptionFunc sets the description func of the multi-select field.
func (*MultiSelect[T]) Error ¶
func (m *MultiSelect[T]) Error() error
Error returns the error of the multi-select field.
func (*MultiSelect[T]) Filterable ¶
func (m *MultiSelect[T]) Filterable(filterable bool) *MultiSelect[T]
Filterable sets the multi-select field as filterable.
func (*MultiSelect[T]) Filtering ¶
func (m *MultiSelect[T]) Filtering(filtering bool) *MultiSelect[T]
Filtering sets the filtering state of the multi-select field.
func (*MultiSelect[T]) Focus ¶
func (m *MultiSelect[T]) Focus() tea.Cmd
Focus focuses the multi-select field.
func (*MultiSelect[T]) GetKey ¶
func (m *MultiSelect[T]) GetKey() string
GetKey returns the multi-select's key.
func (*MultiSelect[T]) GetValue ¶
func (m *MultiSelect[T]) GetValue() any
GetValue returns the multi-select's value.
func (*MultiSelect[T]) Height ¶
func (m *MultiSelect[T]) Height(height int) *MultiSelect[T]
Height sets the height of the multi-select field.
func (*MultiSelect[T]) Init ¶
func (m *MultiSelect[T]) Init() tea.Cmd
Init initializes the multi-select field.
func (*MultiSelect[T]) Key ¶
func (m *MultiSelect[T]) Key(key string) *MultiSelect[T]
Key sets the key of the select field which can be used to retrieve the value after submission.
func (*MultiSelect[T]) KeyBinds ¶
func (m *MultiSelect[T]) KeyBinds() []key.Binding
KeyBinds returns the help message for the multi-select field.
func (*MultiSelect[T]) Limit ¶
func (m *MultiSelect[T]) Limit(limit int) *MultiSelect[T]
Limit sets the limit of the multi-select field.
func (*MultiSelect[T]) Options ¶
func (m *MultiSelect[T]) Options(options ...Option[T]) *MultiSelect[T]
Options sets the options of the multi-select field.
func (*MultiSelect[T]) OptionsFunc ¶
func (m *MultiSelect[T]) OptionsFunc(f func() []Option[T], bindings any) *MultiSelect[T]
OptionsFunc sets the options func of the multi-select field.
func (*MultiSelect[T]) Skip ¶
func (*MultiSelect[T]) Skip() bool
Skip returns whether the multiselect should be skipped or should be blocking.
func (*MultiSelect[T]) Title ¶
func (m *MultiSelect[T]) Title(title string) *MultiSelect[T]
Title sets the title of the multi-select field.
func (*MultiSelect[T]) TitleFunc ¶
func (m *MultiSelect[T]) TitleFunc(f func() string, bindings any) *MultiSelect[T]
TitleFunc sets the title func of the multi-select field.
func (*MultiSelect[T]) Validate ¶
func (m *MultiSelect[T]) Validate(validate func([]T) error) *MultiSelect[T]
Validate sets the validation function of the multi-select field.
func (*MultiSelect[T]) Value ¶
func (m *MultiSelect[T]) Value(value *[]T) *MultiSelect[T]
Value sets the value of the multi-select field.
func (*MultiSelect[T]) View ¶
func (m *MultiSelect[T]) View() string
View renders the multi-select field.
func (*MultiSelect[T]) WithAccessible ¶
func (m *MultiSelect[T]) WithAccessible(accessible bool) Field
WithAccessible sets the accessible mode of the multi-select field.
func (*MultiSelect[T]) WithHeight ¶
func (m *MultiSelect[T]) WithHeight(height int) Field
WithHeight sets the total height of the multi-select field. Including padding and help menu heights.
func (*MultiSelect[T]) WithKeyMap ¶
func (m *MultiSelect[T]) WithKeyMap(k *KeyMap) Field
WithKeyMap sets the keymap of the multi-select field.
func (*MultiSelect[T]) WithPosition ¶
func (m *MultiSelect[T]) WithPosition(p FieldPosition) Field
WithPosition sets the position of the multi-select field.
func (*MultiSelect[T]) WithTheme ¶
func (m *MultiSelect[T]) WithTheme(theme *Theme) Field
WithTheme sets the theme of the multi-select field.
func (*MultiSelect[T]) WithWidth ¶
func (m *MultiSelect[T]) WithWidth(width int) Field
WithWidth sets the width of the multi-select field.
func (*MultiSelect[T]) Zoom ¶
func (*MultiSelect[T]) Zoom() bool
Zoom returns whether the multiselect should be zoomed.
type MultiSelectKeyMap ¶
type MultiSelectKeyMap struct { Next key.Binding Prev key.Binding Up key.Binding Down key.Binding HalfPageUp key.Binding HalfPageDown key.Binding GotoTop key.Binding GotoBottom key.Binding Toggle key.Binding Filter key.Binding SetFilter key.Binding ClearFilter key.Binding Submit key.Binding SelectAll key.Binding SelectNone key.Binding }
MultiSelectKeyMap is the keybindings for multi-select fields.
type Note ¶
type Note struct {
// contains filtered or unexported fields
}
Note is a note field.
A note is responsible for displaying information to the user. Use it to provide context around a different field. Generally, the notes are not interacted with unless the note has a next button `Next(true)`.
func NewNote ¶
func NewNote() *Note
NewNote creates a new note field.
A note is responsible for displaying information to the user. Use it to provide context around a different field. Generally, the notes are not interacted with unless the note has a next button `Next(true)`.
func (*Note) Description ¶
Description sets the note field's description.
This description will be static, for dynamic descriptions use `DescriptionFunc`.
func (*Note) DescriptionFunc ¶
DescriptionFunc sets the description func of the note field.
The DescriptionFunc will be re-evaluated when the binding of the DescriptionFunc changes. This is useful when you want to display dynamic content and update the description of a note when another part of your form changes.
For example, you can make a dynamic markdown preview with the following Form & Group.
huh.NewText().Title("Markdown").Value(&md), huh.NewNote().Height(20).Title("Preview"). DescriptionFunc(func() string { return md }, &md),
Notice the `binding` of the Note is the same as the `Value` of the Text field. This binds the two values together, so that when the `Value` of the Text field changes so does the Note description.
func (*Note) Title ¶
Title sets the note field's title.
This title will be static, for dynamic titles use `TitleFunc`.
func (*Note) TitleFunc ¶
TitleFunc sets the title func of the note field.
The TitleFunc will be re-evaluated when the binding of the TitleFunc changes. This is useful when you want to display dynamic content and update the title of a note when another part of your form changes.
See README.md#Dynamic for more usage information.
func (*Note) WithAccessible ¶
WithAccessible sets the accessible mode of the note field.
func (*Note) WithHeight ¶
WithHeight sets the height of the note field.
func (*Note) WithKeyMap ¶
WithKeyMap sets the keymap on a note field.
func (*Note) WithPosition ¶
func (n *Note) WithPosition(p FieldPosition) Field
WithPosition sets the position information of the note field.
type NoteKeyMap ¶
NoteKeyMap is the keybindings for note fields.
type Option ¶
type Option[T comparable] struct { Key string Value T // contains filtered or unexported fields }
Option is an option for select fields.
func NewOption ¶
func NewOption[T comparable](key string, value T) Option[T]
NewOption returns a new select option.
func NewOptions ¶
func NewOptions[T comparable](values ...T) []Option[T]
NewOptions returns new options from a list of values.
type PointerAccessor ¶
type PointerAccessor[T any] struct { // contains filtered or unexported fields }
PointerAccessor allows field value to be exposed as a pointed variable.
func NewPointerAccessor ¶
func NewPointerAccessor[T any](value *T) *PointerAccessor[T]
NewPointerAccessor returns a new pointer accessor.
type Select ¶
type Select[T comparable] struct { // contains filtered or unexported fields }
Select is a select field.
A select field is a field that allows the user to select from a list of options. The options can be provided statically or dynamically using Options or OptionsFunc. The options can be filtered using "/" and navigation is done using j/k, up/down, or ctrl+n/ctrl+p keys.
func NewSelect ¶
func NewSelect[T comparable]() *Select[T]
NewSelect creates a new select field.
A select field is a field that allows the user to select from a list of options. The options can be provided statically or dynamically using Options or OptionsFunc. The options can be filtered using "/" and navigation is done using j/k, up/down, or ctrl+n/ctrl+p keys.
func (*Select[T]) Description ¶
Description sets the description of the select field.
This description will be static, for dynamic descriptions use `DescriptionFunc`.
func (*Select[T]) DescriptionFunc ¶
DescriptionFunc sets the description func of the select field.
This DescriptionFunc will be re-evaluated when the binding of the DescriptionFunc changes. This is useful when you want to display dynamic content and update the description when another part of your form changes.
See README#Dynamic for more usage information.
func (*Select[T]) Height ¶
Height sets the height of the select field. If the number of options exceeds the height, the select field will become scrollable.
func (*Select[T]) Key ¶
Key sets the key of the select field which can be used to retrieve the value after submission.
func (*Select[T]) Options ¶
Options sets the options of the select field.
This is what your user will select from.
Title Description
-> Option 1 Option 2 Option 3
These options will be static, for dynamic options use `OptionsFunc`.
func (*Select[T]) OptionsFunc ¶
OptionsFunc sets the options func of the select field.
This OptionsFunc will be re-evaluated when the binding of the OptionsFunc changes. This is useful when you want to display dynamic content and update the options when another part of your form changes.
For example, changing the state / provinces, based on the selected country.
huh.NewSelect[string](). Options(huh.NewOptions("United States", "Canada", "Mexico")...). Value(&country). Title("Country"). Height(5), huh.NewSelect[string](). Title("State / Province"). // This can also be made dynamic with `TitleFunc`. OptionsFunc(func() []huh.Option[string] { s := states[country] time.Sleep(1000 * time.Millisecond) return huh.NewOptions(s...) }, &country),
See examples/dynamic/dynamic-country/main.go for the full example.
func (*Select[T]) Title ¶
Title sets the title of the select field.
This title will be static, for dynamic titles use `TitleFunc`.
func (*Select[T]) TitleFunc ¶
TitleFunc sets the title func of the select field.
This TitleFunc will be re-evaluated when the binding of the TitleFunc changes. This when you want to display dynamic content and update the title when another part of your form changes.
See README#Dynamic for more usage information.
func (*Select[T]) WithAccessible ¶
WithAccessible sets the accessible mode of the select field.
func (*Select[T]) WithHeight ¶
WithHeight sets the height of the select field.
func (*Select[T]) WithKeyMap ¶
WithKeyMap sets the keymap on a select field.
func (*Select[T]) WithPosition ¶
func (s *Select[T]) WithPosition(p FieldPosition) Field
WithPosition sets the position of the select field.
type SelectKeyMap ¶
type SelectKeyMap struct { Next key.Binding Prev key.Binding Up key.Binding Down key.Binding HalfPageUp key.Binding HalfPageDown key.Binding GotoTop key.Binding GotoBottom key.Binding Left key.Binding Right key.Binding Filter key.Binding SetFilter key.Binding ClearFilter key.Binding Submit key.Binding }
SelectKeyMap is the keybindings for select fields.
type Text ¶
type Text struct {
// contains filtered or unexported fields
}
Text is a text field.
A text box is responsible for getting multi-line input from the user. Use it to gather longer-form user input. The Text field can be filled with an EDITOR.
func NewText ¶
func NewText() *Text
NewText creates a new text field.
A text box is responsible for getting multi-line input from the user. Use it to gather longer-form user input. The Text field can be filled with an EDITOR.
func (*Text) Description ¶
Description sets the description of the text field.
This description will be static, for dynamic description use `DescriptionFunc`.
func (*Text) DescriptionFunc ¶
DescriptionFunc sets the description func of the text field.
The DescriptionFunc will be re-evaluated when the binding of the DescriptionFunc changes. This is useful when you want to display dynamic content and update the description when another part of your form changes.
See README#Dynamic for more usage information.
func (*Text) Editor ¶
Editor specifies which editor to use.
The first argument provided is used as the editor command (vim, nvim, nano, etc...) The following (optional) arguments provided are passed as arguments to the editor command.
func (*Text) EditorExtension ¶
EditorExtension specifies arguments to pass into the editor.
func (*Text) Placeholder ¶
Placeholder sets the placeholder of the text field.
This placeholder will be static, for dynamic placeholders use `PlaceholderFunc`.
func (*Text) PlaceholderFunc ¶
PlaceholderFunc sets the placeholder func of the text field.
The PlaceholderFunc will be re-evaluated when the binding of the PlaceholderFunc changes. This is useful when you want to display dynamic content and update the placeholder when another part of your form changes.
See README#Dynamic for more usage information.
func (*Text) ShowLineNumbers ¶
ShowLineNumbers sets whether or not to show line numbers.
func (*Text) Title ¶
Title sets the text field's title.
This title will be static, for dynamic titles use `TitleFunc`.
func (*Text) TitleFunc ¶
TitleFunc sets the text field's title func.
The TitleFunc will be re-evaluated when the binding of the TitleFunc changes. This is useful when you want to display dynamic content and update the title when another part of your form changes.
See README#Dynamic for more usage information.
func (*Text) WithAccessible ¶
WithAccessible sets the accessible mode of the text field.
func (*Text) WithHeight ¶
WithHeight sets the height of the text field.
func (*Text) WithKeyMap ¶
WithKeyMap sets the keymap on a text field.
func (*Text) WithPosition ¶
func (t *Text) WithPosition(p FieldPosition) Field
WithPosition sets the position information of the text field.
type TextInputStyles ¶
type TextInputStyles struct { Cursor lipgloss.Style CursorText lipgloss.Style Placeholder lipgloss.Style Prompt lipgloss.Style Text lipgloss.Style }
TextInputStyles are the styles for text inputs.
type TextKeyMap ¶
type TextKeyMap struct { Next key.Binding Prev key.Binding NewLine key.Binding Editor key.Binding Submit key.Binding }
TextKeyMap is the keybindings for text fields.
type Theme ¶
type Theme struct { Form lipgloss.Style Group lipgloss.Style FieldSeparator lipgloss.Style Blurred FieldStyles Focused FieldStyles Help help.Styles }
Theme is a collection of styles for components of the form. Themes can be applied to a form using the WithTheme option.
func ThemeBase ¶
func ThemeBase() *Theme
ThemeBase returns a new base theme with general styles to be inherited by other themes.
func ThemeBase16 ¶
func ThemeBase16() *Theme
ThemeBase16 returns a new theme based on the base16 color scheme.
func ThemeCatppuccin ¶
func ThemeCatppuccin() *Theme
ThemeCatppuccin returns a new theme based on the Catppuccin color scheme.
func ThemeCharm ¶
func ThemeCharm() *Theme
ThemeCharm returns a new theme based on the Charm color scheme.
func ThemeDracula ¶
func ThemeDracula() *Theme
ThemeDracula returns a new theme based on the Dracula color scheme.