Documentation ¶
Overview ¶
Package promptui provides ui elements for the command line prompt.
Index ¶
Constants ¶
const ( FGBold attribute FGFaint FGItalic FGUnderline )
Foreground weight/decoration attributes.
const ( FGBlack attribute = iota + 30 FGRed FGGreen FGYellow FGBlue FGMagenta FGCyan FGWhite )
Foreground color attributes
const SelectedAdd = -1
SelectedAdd is returned from SelectWithAdd when add is selected.
Variables ¶
var ( IconInitial = Styler(FGBlue)("?") IconGood = Styler(FGGreen)("v") IconWarn = Styler(FGYellow)("!") IconBad = Styler(FGRed)("x") IconSelect = Styler(FGBold)(">") )
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 FuncMap = template.FuncMap{ "black": Styler(FGBlack), "red": Styler(FGRed), "green": Styler(FGGreen), "yellow": Styler(FGYellow), "blue": Styler(FGBlue), "magenta": Styler(FGMagenta), "cyan": Styler(FGCyan), "white": Styler(FGWhite), "bold": Styler(FGBold), "faint": Styler(FGFaint), "italic": Styler(FGItalic), "underline": Styler(FGUnderline), }
FuncMap defines template helpers for the output. It can be extended as a regular map.
var ResetCode = fmt.Sprintf("%s%dm", esc, reset)
ResetCode is the character code used to reset the terminal formatting
Functions ¶
Types ¶
type Prompt ¶
type Prompt struct { // Label is the value displayed on the command line prompt. It can be any // value one would pass to a text/template Execute(), including just a string. Label interface{} 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 // If mask is set, this value is displayed instead of the actual input // characters. Mask rune // Templates can be used to customize the prompt output. If nil is passed, the // default templates are used. Templates *PromptTemplates IsConfirm bool IsVimMode bool // contains filtered or unexported fields }
Prompt represents a single line text field input.
type PromptTemplates ¶
type PromptTemplates struct { // Prompt is a text/template for the initial prompt question. Prompt string // Prompt is a text/template if the prompt is a confirmation. Confirm string // Valid is a text/template for when the current input is valid. Valid string // Invalid is a text/template for when the current input is invalid. Invalid string // Success is a text/template for the successful result. Success string // Prompt is a text/template when there is a validation error. ValidationError string // FuncMap is a map of helpers for the templates. If nil, the default helpers // are used. FuncMap template.FuncMap // contains filtered or unexported fields }
PromptTemplates allow a prompt to be customized following stdlib text/template syntax. If any field is blank a default template is used.
type Select ¶
type Select struct { // Label is the value displayed on the command line prompt. It can be any // value one would pass to a text/template Execute(), including just a string. Label interface{} // Items are the items to use in the list. It can be any slice type one would // pass to a text/template execute, including a string slice. Items interface{} // Size is the number of items that should appear on the select before // scrolling. If it is 0, defaults to 5. Size int // IsVimMode sets whether readline is using Vim mode. IsVimMode bool // Templates can be used to customize the select output. If nil is passed, the // default templates are used. Templates *SelectTemplates // contains filtered or unexported fields }
Select represents a list for selecting a single item
type SelectTemplates ¶
type SelectTemplates struct { // Active is a text/template for the label. Label string // Active is a text/template for when an item is current active. Active string // Inactive is a text/template for when an item is not current active. Inactive string // Selected is a text/template for when an item was successfully selected. Selected string // Details is a text/template for when an item current active to show // additional information. It can have multiple lines. Details string // FuncMap is a map of helpers for the templates. If nil, the default helpers // are used. FuncMap template.FuncMap // contains filtered or unexported fields }
SelectTemplates allow a select prompt to be customized following stdlib text/template syntax. If any field is blank a default template is used.
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.