Documentation
¶
Index ¶
- Variables
- func SetDefaultAnswerFunc(fn func(string) string)
- func SetDefaultCursorFunc(fn func(string) string)
- func SetDefaultIconFunc(fn func(string) string)
- func SetDefaultSelectFunc(fn func(string) string)
- func SetDefaultTitleFunc(fn func(string) string)
- type Confirm
- func (c *Confirm) AnswerFunc(fn func(string) string) *Confirm
- func (c *Confirm) Ask() error
- func (c *Confirm) Icon(s string) *Confirm
- func (c *Confirm) IconFunc(fn func(string) string) *Confirm
- func (c *Confirm) Title(title string) *Confirm
- func (c *Confirm) TitleFunc(fn func(string) string) *Confirm
- func (c *Confirm) Value(value *bool) *Confirm
- type Form
- type Option
- type Password
- func (p *Password) AnswerFunc(fn func(string) string) *Password
- func (p *Password) Ask() error
- func (p *Password) Icon(s string) *Password
- func (p *Password) IconFunc(fn func(string) string) *Password
- func (p *Password) Title(title string) *Password
- func (p *Password) TitleFunc(fn func(string) string) *Password
- func (p *Password) Validate(fn func([]byte) error) *Password
- func (p *Password) Value(value *[]byte) *Password
- type Prompt
- type Question
- func (q *Question) AnswerFunc(fn func(string) string) *Question
- func (q *Question) Ask() error
- func (q *Question) Icon(s string) *Question
- func (q *Question) IconFunc(fn func(string) string) *Question
- func (q *Question) Title(title string) *Question
- func (q *Question) TitleFunc(fn func(string) string) *Question
- func (q *Question) Validate(fn func(string) error) *Question
- func (q *Question) Value(value *string) *Question
- type Select
- func (sel *Select[T]) AnswerFunc(fn func(string) string) *Select[T]
- func (sel *Select[T]) Ask() error
- func (sel *Select[T]) Cursor(cursor string) *Select[T]
- func (sel *Select[T]) CursorFunc(fn func(string) string) *Select[T]
- func (sel *Select[T]) Icon(icon string) *Select[T]
- func (sel *Select[T]) IconFunc(fn func(string) string) *Select[T]
- func (sel *Select[T]) Options(options ...Option[T]) *Select[T]
- func (sel *Select[T]) SelectFunc(fn func(string) string) *Select[T]
- func (sel *Select[T]) Title(title string) *Select[T]
- func (sel *Select[T]) TitleFunc(fn func(string) string) *Select[T]
- func (sel *Select[T]) Value(value *T) *Select[T]
Constants ¶
This section is empty.
Variables ¶
var ( ErrUserAborted = errors.New("user aborted") ErrNoTitle = errors.New("prompt requires a title") ErrNoSelectOptions = errors.New("select prompt requires at least one option") ErrNoValue = errors.New("value must be set") )
var Icons = icons{
Alert: "[!] ",
QuestionMark: "[?] ",
Password: "🔒 ",
}
Icons contains default icons for different prompt types.
Functions ¶
func SetDefaultAnswerFunc ¶
SetDefaultAnswerFunc sets the global default answer transformation function.
func SetDefaultCursorFunc ¶
SetDefaultCursorFunc sets the global default cursor formatting function.
func SetDefaultIconFunc ¶
SetDefaultIconFunc sets the global default icon transformation function.
func SetDefaultSelectFunc ¶
SetDefaultSelectFunc sets the global default selection formatting function.
func SetDefaultTitleFunc ¶
SetDefaultTitleFunc sets the global default title transformation function.
Types ¶
type Confirm ¶
type Confirm struct {
// contains filtered or unexported fields
}
Confirm represents a yes/no confirmation prompt for user decisions.
func NewConfirm ¶
NewConfirm creates a new Confirm prompt instance.
func (*Confirm) AnswerFunc ¶
AnswerFunc sets a function to transform the final answer before returning.
type Form ¶
type Form struct {
// contains filtered or unexported fields
}
Form represents a collection of prompts executed sequentially.
type Option ¶
type Option[T comparable] struct { Key string // Display label Value T // Associated value }
Option represents a selectable key-value pair for use in selection prompts.
func NewOption ¶
func NewOption[T comparable](key string, value T) Option[T]
NewOption creates a new Option with the given key and value.
type Password ¶
type Password struct {
// contains filtered or unexported fields
}
Password represents a password input prompt that securely collects sensitive information.
func NewPassword ¶
NewPassword creates a new Password prompt instance.
func (*Password) AnswerFunc ¶
AnswerFunc sets a function to transform the final answer before returning.
type Prompt ¶
type Prompt interface { // Ask displays the prompt and waits for user input. Ask() error }
Prompt is the interface implemented by all prompt types.
type Question ¶
type Question struct {
// contains filtered or unexported fields
}
Question represents a text input prompt for user questions.
func NewQuestion ¶
NewQuestion creates a new Question prompt instance.
func (*Question) AnswerFunc ¶
AnswerFunc sets a function to transform the final answer.
type Select ¶
type Select[T comparable] struct { // contains filtered or unexported fields }
Select represents a multiple-choice selection prompt.
func NewSelect ¶
func NewSelect[T comparable](value *T) *Select[T]
NewSelect creates a new Select prompt instance.
func (*Select[T]) AnswerFunc ¶
AnswerFunc sets a function to format the final answer display.
func (*Select[T]) CursorFunc ¶
CursorFunc sets a function to dynamically format the cursor symbol.
func (*Select[T]) SelectFunc ¶
SelectFunc sets a function to format option text during selection.