terminal

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2021 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Output    = colorable.NewColorableStdout()
	ErrOutput = colorable.NewColorableStderr()

	TerminalSupportsColors = isTerminal()
	UserAskedForColors     = ""
)
View Source
var (
	ErrInputEmpty          = errors.New("input is empty")
	ErrInputNotNumber      = errors.New("input is not a number")
	ErrInputNotFloatNumber = errors.New("input is not a floating point number")
	ErrInputNotBool        = errors.New("input must be 'y', 'n', 'yes' or 'no'")
	ErrInputOutOfRange     = errors.New("input is out of range")
)

Functions

func AdvisoryColor

func AdvisoryColor(message string) string

func Colorize

func Colorize(message string, color *color.Color) string

func ColorsEnabled

func ColorsEnabled() bool

func CommandColor

func CommandColor(message string) string

func CrashedColor

func CrashedColor(message string) string

func Decolorize

func Decolorize(message string) string

func EntityNameColor

func EntityNameColor(message string) string

func FailureColor

func FailureColor(message string) string

func HeaderColor

func HeaderColor(message string) string

func InitColorSupport

func InitColorSupport()

func LogAppHeaderColor

func LogAppHeaderColor(message string) string

func LogHealthHeaderColor

func LogHealthHeaderColor(message string) string

func LogStderrColor

func LogStderrColor(message string) string

func LogStdoutColor

func LogStdoutColor(message string) string

func LogSysHeaderColor

func LogSysHeaderColor(message string) string

func PromptColor

func PromptColor(message string) string

func StoppedColor

func StoppedColor(message string) string

func SuccessColor

func SuccessColor(message string) string

func TableContentHeaderColor

func TableContentHeaderColor(message string) string

func WarningColor

func WarningColor(message string) string

Types

type PrintableTable

type PrintableTable struct {
	// contains filtered or unexported fields
}

func (*PrintableTable) Add

func (t *PrintableTable) Add(row ...string)

func (*PrintableTable) Print

func (t *PrintableTable) Print()

type Prompt

type Prompt struct {
	Reader io.Reader
	Writer io.Writer
	// contains filtered or unexported fields
}

Prompt represents a terminal prompt. Create Prompt with NewPrompt or NewChoicesPrompt

func NewChoicesPrompt

func NewChoicesPrompt(message string, choices []string, options *PromptOptions) *Prompt

NewChoicesPrompt returns a choice prompt

func NewPrompt

func NewPrompt(message string, options *PromptOptions) *Prompt

NewPrompt returns a single prompt

func (*Prompt) Resolve

func (p *Prompt) Resolve(dest interface{}) error

Resolve reads user input and resolves it to the destination value

type PromptOptions

type PromptOptions struct {
	Required     bool         // If true, user input is required
	HideInput    bool         // If true, user input is hide, typically when asking password. TODO: support mask later
	HideDefault  bool         // If true, hide default value in the prompt message
	NoLoop       bool         // if true, when input is invalid, return error instead of asking user for retry
	ValidateFunc ValidateFunc // customized input validation function
}

type Table

type Table interface {
	Add(row ...string)
	Print()
}

func NewTable

func NewTable(w io.Writer, headers []string) Table

type UI

type UI interface {
	// Deprecated: this method could be removed in the future,
	// Use Info() if the message is printed to StdErr and it will be suppressed in quiet mode
	// Or use Verbose() if the message is printed to StdOut and it will be suppressed in quiet mode
	// Say prints the formated message to StdOut, the message will NOT be suppressed in quiet mode
	Say(format string, args ...interface{})

	// Verbose prints message to StdOut, the message will be suppressed in quiet mode
	Verbose(format string, args ...interface{})

	// Info prints message to StdErr, the message will be suppressed in quiet mode
	Info(format string, args ...interface{})

	// Warn prints the formated warning message to StdErr, the message will be suppressed in quiet mode
	Warn(format string, args ...interface{})

	// Failed prints the formated failure message to StdErr, word `FAILED` will be suppressed in quiet mode.
	// But the message itself will NOT be suppressed.
	Failed(format string, args ...interface{})

	// Print will send the message to StdOut, the message will NOT be suppressed in quiet mode
	Print(format string, args ...interface{})

	// OK prints 'OK' to StdOut, the message will be suppressed in quiet mode
	Ok()

	// Prompt creates a single Prompt
	Prompt(message string, options *PromptOptions) *Prompt

	// ChoicePrompt creates a choice prompt
	ChoicesPrompt(message string, choices []string, options *PromptOptions) *Prompt

	// Ask asks for text answer
	// Deprecated: use Prompt instead
	Ask(format string, args ...interface{}) (answer string, err error)

	// AskForPassword asks for password
	// Deprecated: use Prompt instead
	AskForPassword(format string, args ...interface{}) (answer string, err error)

	// Confirm asks for user confirmation
	// Deprecated: use Prompt instead
	Confirm(format string, args ...interface{}) (bool, error)

	// ConfirmWithDefault asks for user confirmation. If user skipped, return
	// defaultBool Deprecated: use Prompt instead
	ConfirmWithDefault(defaultBool bool, format string, args ...interface{}) (bool, error)

	// SelectOne asks to select one from choices. It returns the selected index.
	// Deprecated: use ChoicesPrompt instead
	SelectOne(choices []string, format string, args ...interface{}) (int, error)

	// Table creates a table with the given headers
	Table(headers []string) Table

	// Writer returns writer of the terminal UI
	Writer() io.Writer

	// Enable or disable quiet mode. Contents passed to Verbose(), Warn(), OK() will be ignored if under quiet mode.
	SetQuiet(bool)

	// Return whether quiet mode is enabled or not
	Quiet() bool
}

UI provides utilities to handle input and output streams

func NewStdUI

func NewStdUI() UI

NewStdUI initialize a terminal UI with os.Stdin and os.Stdout

func NewUI

func NewUI(in io.Reader, out io.Writer, errOut io.Writer) UI

NewUI initialize a terminal UI with io.Reader and io.Writer

type ValidateFunc

type ValidateFunc func(string) error

Jump to

Keyboard shortcuts

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