promptui

package
v0.21.0 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2016 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Overview

Package promptui provides ui elements for the command line prompt.

Index

Constants

View Source
const SelectedAdd = -1

SelectedAdd is returned from SelectWithAdd when add is selected.

Variables

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.

Functions

func FailedValue

func FailedValue(label, value string) string

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

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
	// 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