Documentation
¶
Overview ¶
Package promptui provides ui elements for the command line prompt.
Index ¶
- Constants
- Variables
- func Ask(label, startString string) (string, error)
- func AskMasked(label, startString string) (string, error)
- func ClearUpLine() string
- func ClearUpLines(n int) string
- func Confirm(label, answer string, noIcons bool) (string, error)
- func Editor(editor, s string) (string, error)
- func FailedValue(label, value string) string
- func MultiLine(label, answer string) (string, error)
- func PromptAfterSelect(label string, answers []string) (string, error)
- func Styler(attrs ...attribute) func(string) string
- func SuccessfulValue(label, value string) string
- func UpLine() string
- type BasicPrompt
- type ConfirmPrompt
- type IconSet
- type InputStyle
- type LabelStyle
- type MultilinePrompt
- type Prompt
- type PromptStyle
- type Select
- type SelectWithAdd
- type StyleFn
- type ValidateFunc
- type ValidationError
Constants ¶
const ( FGBold attribute FGFaint FGItalic FGUnderline )
Forground weight/decoration attributes.
const ( FGBlack attribute = iota + 30 FGRed FGGreen FGYellow FGBlue FGMagenta FGCyan FGWhite )
Forground color attributes
const SelectedAdd = -1
SelectedAdd is returned from SelectWithAdd when add is selected.
Variables ¶
var ( // ErrorOpen describes open editor error ErrorOpen = errors.New("in promptui:Editor: Error open temp file") // ErrorWrite describes write editor error ErrorWrite = errors.New("in promptui:Editor: Error write temp file") // ErrorRead describes read editor error ErrorRead = errors.New("in promptui:Editor: Error read temp file") // ErrorClose describes close editor error ErrorClose = errors.New("in promptui:Editor: Error close temp file") )
var ( IconInitial = Styler(FGBlue)("?") IconGood = Styler(FGGreen)("✔") IconQuest = Styler(FGBlue)("✔") IconWarn = Styler(FGYellow)("⚠") IconBad = Styler(FGRed)("✗") )
Icons used for displaying prompts or status
var ErrAbort = errors.New("")
ErrAbort is returned when confirm prompts are supplied "n"
var ErrEOF = errors.New("^D")
ErrEOF is returned from prompts when EOF is encountered.
var ErrInterrupt = errors.New("^C")
ErrInterrupt is returned from prompts when an interrupt (ctrl-c) is encountered.
var ( // ErrorIncorrect describes incorrect default confirm value ErrorIncorrect = errors.New("Incorrect default values") )
var ResetCode = fmt.Sprintf("%s%dm", esc, reset)
ResetCode is the character code used to reset the terminal formatting
Functions ¶
func Editor ¶
Editor func opens default editor to edit `s string`. Returns edit result. Creates temp file to edit string
func FailedValue ¶
FailedValue returns a value as if it were entered via prompt, invalid
func PromptAfterSelect ¶
PromptAfterSelect func is predefined easy confirm promp Answers may contain option description wrapped in `[]`
func Styler ¶
Styler returns a func that applies the attributes given in the Styler call to the provided string.
func SuccessfulValue ¶
SuccessfulValue returns a value as if it were entered via prompt, valid
Types ¶
type BasicPrompt ¶
type BasicPrompt struct { Label string // Label is the value displayed on the command line prompt Default string // Default is the initial value to populate in the prompt // Validate is optional. If set, this function is used to validate the input // after each character entry. Validate ValidateFunc // Indent will be placed before the prompt's state symbol Indent string // InterruptPrompt to send to readline InterruptPrompt string // NoIcons flag to set empty string icons NoIcons bool // IconSet contains prompt icons IconSet // LabelStyle contains Label styles LabelStyle // InputStyle contains Input styles InputStyle // PromptStyle contains Prompt styles PromptStyle // IsVimMode option IsVimMode bool // Preamble option Preamble *string // Formatter formats input result Formatter StyleFn // contains filtered or unexported fields }
BasicPrompt represents a single line text field input.
type ConfirmPrompt ¶
type ConfirmPrompt struct { BasicPrompt // ConfirmOpt is the 3d answer option ConfirmOpt string // contains filtered or unexported fields }
ConfirmPrompt represents a single line text field input.
func (*ConfirmPrompt) Run ¶
func (cp *ConfirmPrompt) Run() (string, error)
Run func implements confirn prompt
type IconSet ¶
type IconSet struct { // IconInitial icon to render IconInitial string // IconGood icon to render IconGood string // IconQuest icon to render IconQuest string // IconWarn icon to render IconWarn string // IconBad icon to render IconBad string }
IconSet struct holds all inner icons to render
type InputStyle ¶
type InputStyle struct { // InputInitial styler for initial Input text InputInitial StyleFn // InputResult styler for result Input text InputResult StyleFn }
InputStyle contains Input styles
type LabelStyle ¶
type LabelStyle struct { // LabelInitial styler for initial Label text LabelInitial StyleFn // LabelResult styler for result Label text LabelResult StyleFn }
LabelStyle contains Label styles
type MultilinePrompt ¶
type MultilinePrompt struct { BasicPrompt // OnError func is called when prompt.Run() return error // alternative way to fix error OnError func(string) (string, error) // Editor is default editor to edit multiline Editor string }
MultilinePrompt represents a single line text field input.
func (*MultilinePrompt) Run ¶
func (mp *MultilinePrompt) Run() (string, error)
Run func implements multiline prompt logic
type Prompt ¶
type Prompt struct { BasicPrompt // If mask is set, this value is displayed instead of the actual input // characters. Mask rune // Handlers catch key input events, user defined Handlers []func(line []rune, pos int, key rune) ([]rune, int, bool) }
Prompt represents a single line text field input.
type PromptStyle ¶
type PromptStyle struct { // PromptInitial styler for initial Prompt text PromptInitial StyleFn // PromptResult styler for result Prompt text PromptResult StyleFn }
PromptStyle contains Prompt styles for including label, punctuation, suggested
type Select ¶
type Select struct { Label string // Label is the value displayed on the command line prompt. Items []string // Items are the items to use in the list. Default int // Index of default item starting from 0 IsVimMode bool // Whether readline is using Vim mode. }
Select represents a list for selecting a single item
type SelectWithAdd ¶
type SelectWithAdd struct { Label string // Label is the value displayed on the command line prompt. Items []string // Items are the items to use in the list. AddLabel string // The label used in the item list for creating a new item. // Validate is optional. If set, this function is used to validate the input // after each character entry. Validate ValidateFunc IsVimMode bool // Whether readline is using Vim mode. }
SelectWithAdd represents a list for selecting a single item, or selecting a newly created item.
type ValidateFunc ¶
ValidateFunc validates the given input. It should return a ValidationError if the input is not valid.
type ValidationError ¶
type ValidationError struct {
// contains filtered or unexported fields
}
ValidationError is the class of errors resulting from invalid inputs, returned from a ValidateFunc.
func NewValidationError ¶
func NewValidationError(msg string) *ValidationError
NewValidationError creates a new validation error with the given message.
func (*ValidationError) Error ¶
func (v *ValidationError) Error() string
Error implements the error interface for ValidationError.