ui

package
v0.18.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 17, 2021 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// IconInitial is the icon used when starting in prompt mode and the icon next to the label when
	// starting in select mode.
	IconInitial = promptui.Styler(promptui.FGBlue)("?")

	// IconGood is the icon used when a good answer is entered in prompt mode.
	IconGood = promptui.Styler(promptui.FGGreen)("✔")

	// IconWarn is the icon used when a good, but potentially invalid answer is entered in prompt mode.
	IconWarn = promptui.Styler(promptui.FGYellow)("⚠")

	// IconBad is the icon used when a bad answer is entered in prompt mode.
	IconBad = promptui.Styler(promptui.FGRed)("✗")

	// IconSelect is the icon used to identify the currently selected item in select mode.
	IconSelect = promptui.Styler(promptui.FGBold)("▸")
)

Functions

func Address

func Address() promptui.ValidateFunc

Address is a validation function that checks that the prompted string is a valid TCP address.

func DNS

func DNS() promptui.ValidateFunc

DNS is a validation function that changes that the prompted string is a valid DNS name.

func IPAddress

func IPAddress() promptui.ValidateFunc

IPAddress is validation function that checks that the prompted string is a valid IP address.

func NamedSelectTemplates

func NamedSelectTemplates(name string) *promptui.SelectTemplates

NamedSelectTemplates returns the default promptui.SelectTemplate for struct slices with a name property. The given name is the prompt of the selected option.

func NotEmpty

func NotEmpty() promptui.ValidateFunc

NotEmpty is a validation function that checks that the prompted string is not empty.

func Print added in v0.15.14

func Print(args ...interface{}) error

Print uses templates to print the arguments formated to os.Stderr.

func PrintSelected

func PrintSelected(name, value string, opts ...Option) error

PrintSelected prints the given name and value as if they were selected from a promptui.Select.

func PrintSelectedTemplate

func PrintSelectedTemplate() string

PrintSelectedTemplate returns the default template used in PrintSelected.

func Printf

func Printf(format string, args ...interface{}) error

Printf uses templates to print the string formated to os.Stderr.

func Println

func Println(args ...interface{}) error

Println uses templates to print the given arguments to os.Stderr

func Prompt

func Prompt(label string, opts ...Option) (string, error)

Prompt creates and runs a promptui.Prompt with the given label.

func PromptPassword

func PromptPassword(label string, opts ...Option) ([]byte, error)

PromptPassword creates and runs a promptui.Prompt with the given label. This prompt will mask the key entries with \r.

func PromptPasswordGenerate

func PromptPasswordGenerate(label string, opts ...Option) ([]byte, error)

PromptPasswordGenerate creates and runs a promptui.Prompt with the given label. This prompt will mask the key entries with \r. If the result password length is 0, it will generate a new prompt with a generated password that can be edited.

func PromptTemplates

func PromptTemplates() *promptui.PromptTemplates

PromptTemplates is the default style for a prompt.

func PromptYesNo added in v0.15.5

func PromptYesNo(label string, opts ...Option) (bool, error)

PromptYesNo creates and runs a promptui.Prompt with the given label, and returns true if the answer is y/yes and false if the answer is n/no.

func Select

func Select(label string, items interface{}, opts ...Option) (int, string, error)

Select creates and runs a promptui.Select with the given label and items.

func SelectTemplates

func SelectTemplates(name string) *promptui.SelectTemplates

SelectTemplates returns the default promptui.SelectTemplate for string slices. The given name is the prompt of the selected option.

func SimplePromptTemplates

func SimplePromptTemplates() *promptui.PromptTemplates

SimplePromptTemplates is a prompt with a simple style, used by default on password prompts.

func YesNo

func YesNo() promptui.ValidateFunc

YesNo is a validation function that checks for a Yes/No answer.

Types

type Option

type Option func(*options)

Option is the type of the functions that modify the prompt options.

func WithAllowEdit

func WithAllowEdit(b bool) Option

WithAllowEdit if true, let's the user edit the default value set.

func WithDefaultValue

func WithDefaultValue(s string) Option

WithDefaultValue adds a custom string as the default value.

func WithMask

func WithMask(r rune) Option

WithMask adds a mask to a prompt.

func WithPrintTemplate

func WithPrintTemplate(template string) Option

WithPrintTemplate sets the template to use on the print methods.

func WithPromptTemplates

func WithPromptTemplates(t *promptui.PromptTemplates) Option

WithPromptTemplates adds a custom template to a prompt.

func WithRichPrompt

func WithRichPrompt() Option

WithRichPrompt add the template option with rich templates.

func WithSelectTemplates

func WithSelectTemplates(t *promptui.SelectTemplates) Option

WithSelectTemplates adds a custom template to a select.

func WithSimplePrompt

func WithSimplePrompt() Option

WithSimplePrompt add the template option with simple templates.

func WithSliceValue added in v0.17.3

func WithSliceValue(values []string) Option

WithSliceValue sets a custom string as the result of a prompt. If value is set, the prompt won't be displayed.

func WithValidateFunc

func WithValidateFunc(fn func(string) error) Option

WithValidateFunc adds a custom validation function to a prompt.

func WithValidateNotEmpty

func WithValidateNotEmpty() Option

WithValidateNotEmpty adds a custom validation function to a prompt that checks that the propted string is not empty.

func WithValidateRegexp added in v0.15.5

func WithValidateRegexp(re string) Option

WithValidateRegexp checks a prompt answer with a regular expression. If the regular expression is not a valid one, the option will panic.

func WithValidateYesNo

func WithValidateYesNo() Option

WithValidateYesNo adds a custom validation function to a prompt for a Yes/No prompt.

func WithValue added in v0.8.4

func WithValue(value string) Option

WithValue sets a custom string as the result of a prompt. If value is set, the prompt won't be displayed.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL