Documentation
¶
Index ¶
- Variables
- func ClearLines(n int)
- func TerminalSize() (width, height int)
- type DefaultValue
- type DefaultValueProps
- type Direction
- type Form
- type FormElementer
- type FormInput
- type FormSelect
- type SelectProps
- type Selection
- func (s *Selection[E]) Render() error
- func (s *Selection[E]) RenderWithTheme(themeName Theme) error
- func (s *Selection[E]) Selected() E
- func (s *Selection[E]) SelectedOption() string
- func (s *Selection[E]) SetSelected(p int)
- func (s *Selection[E]) SetShowing(n int)
- func (s *Selection[E]) SetTheme(t Theme)
- type Theme
- type Toggle
Constants ¶
This section is empty.
Variables ¶
var AllTheme = []Theme{ ThemeNerdFont, ThemeAscii, ThemeColor01, ThemeInverted, }
var (
ErrAborted = errors.New("aborted")
)
Functions ¶
func ClearLines ¶
func ClearLines(n int)
ClearLines clears the specified number of lines in the console.
func TerminalSize ¶
func TerminalSize() (width, height int)
TerminalSize returns the visible dimensions of the given terminal. When size could not be retrieved, weight 80 and height 24 is returned.
Types ¶
type DefaultValue ¶
type DefaultValueProps ¶
type DefaultValueProps struct {
SelectOption any
}
type Form ¶
type Form struct { Elements []FormElementer // contains filtered or unexported fields }
func (*Form) AddElements ¶
func (f *Form) AddElements(elements ...FormElementer)
type FormElementer ¶
type FormElementer interface { Label() string Name() string Value() any DefaultValue(func(props *DefaultValueProps) DefaultValue) FormElementer AddValidator(func(value any) error) FormElementer // contains filtered or unexported methods }
type FormInput ¶
type FormInput struct {
// contains filtered or unexported fields
}
func NewFormInput ¶
func (*FormInput) AddValidator ¶
func (fi *FormInput) AddValidator(f func(value any) error) FormElementer
func (*FormInput) DefaultValue ¶
func (fi *FormInput) DefaultValue(f func(props *DefaultValueProps) DefaultValue) FormElementer
type FormSelect ¶
type FormSelect struct {
// contains filtered or unexported fields
}
func NewFormSelect ¶
func NewFormSelect(name, label string, dest any, props SelectProps) *FormSelect
func (*FormSelect) AddValidator ¶
func (fs *FormSelect) AddValidator(f func(value any) error) FormElementer
func (*FormSelect) DefaultValue ¶
func (fs *FormSelect) DefaultValue(f func(props *DefaultValueProps) DefaultValue) FormElementer
type SelectProps ¶
type Selection ¶
type Selection[E any] struct { // contains filtered or unexported fields }
Selection represents a selectable list of options with corresponding values. A user can use the Up- and Down-cursor keys to select an option, and push Enter to confirm the selection.
By default, the `ascii` theme is used, but a Nerd Font theme `nerdfont` is also available.
func NewSelection ¶
func (*Selection[E]) RenderWithTheme ¶
RenderWithTheme renders the Selection with the specified theme. If the theme with the given name does not exist, the default theme of the Selection is used.
func (*Selection[E]) Selected ¶
func (s *Selection[E]) Selected() E
Selected returns the currently selected option from the Selection.
func (*Selection[E]) SelectedOption ¶
SelectedOption returns the currently selected option from the Selection.
func (*Selection[E]) SetSelected ¶
func (*Selection[E]) SetShowing ¶
SetShowing sets the number of options to be shown in the selection. If n is less than 1, it sets the number of options to the terminal height minus 3. Otherwise, it sets the number of options to n.
type Toggle ¶
type Toggle[T any] struct { // contains filtered or unexported fields }
func (*Toggle[T]) RenderWithTheme ¶
RenderWithTheme renders the Selection with the specified theme. If the theme with the given name does not exist, the default theme of the Selection is used.