promptui

package
v0.0.0-...-7b32287 Latest Latest
Warning

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

Go to latest
Published: May 27, 2018 License: MIT Imports: 8 Imported by: 1

Documentation

Overview

Package promptui provides ui elements for the command line prompt.

Index

Constants

View Source
const (
	FGBold attribute
	FGFaint
	FGItalic
	FGUnderline
)

Forground weight/decoration attributes.

View Source
const (
	FGBlack attribute = iota + 30
	FGRed
	FGGreen
	FGYellow
	FGBlue
	FGMagenta
	FGCyan
	FGWhite
)

Forground color attributes

View Source
const SelectedAdd = -1

SelectedAdd is returned from SelectWithAdd when add is selected.

Variables

View Source
var (
	IconInitial = Styler(FGBlue)("?")
	IconGood    = Styler(FGGreen)("✔")
	IconWarn    = Styler(FGYellow)("⚠")
	IconBad     = Styler(FGRed)("✗")
)

Icons used for displaying prompts or status

View Source
var ErrAbort = errors.New("")

ErrAbort is returned when confirm prompts are supplied "n"

View Source
var ErrEOF = errors.New("^D")

ErrEOF is returned from prompts when EOF is encountered.

View Source
var ErrInterrupt = errors.New("^C")

ErrInterrupt is returned from prompts when an interrupt (ctrl-c) is encountered.

View Source
var ResetCode = fmt.Sprintf("%s%dm", esc, reset)

ResetCode is the character code used to reset the terminal formatting

Functions

func FailedValue

func FailedValue(label, value string) string

FailedValue returns a value as if it were entered via prompt, invalid

func Styler

func Styler(attrs ...attribute) func(string) string

Styler returns a func that applies the attributes given in the Styler call to the provided string.

func SuccessfulValue

func SuccessfulValue(label, value string) string

SuccessfulValue returns a value as if it were entered via prompt, valid

Types

type Prompt

type Prompt 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

	// If mask is set, this value is displayed instead of the actual input
	// characters.
	Mask rune

	IsConfirm bool
	IsVimMode bool
	Preamble  *string

	// Indent will be placed before the prompt's state symbol
	Indent string
	// contains filtered or unexported fields
}

Prompt represents a single line text field input.

func (*Prompt) Run

func (p *Prompt) Run() (string, error)

Run runs the prompt, returning the validated input.

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.
	IsVimMode bool     // Whether readline is using Vim mode.
}

Select represents a list for selecting a single item

func (*Select) Run

func (s *Select) Run() (int, string, error)

Run runs the Select list. It returns the index of the selected element, and its value.

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.

func (*SelectWithAdd) Run

func (sa *SelectWithAdd) Run() (int, string, error)

Run runs the Select list. It returns the index of the selected element, and its value. If a new element is created, -1 is returned as the index.

type ValidateFunc

type ValidateFunc func(string) error

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.

Jump to

Keyboard shortcuts

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