ui

package
v6.23.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2016 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package ui will provide hooks into STDOUT, STDERR and STDIN. It will also handle translation as necessary.

This package is explicitly designed for the CF CLI and is *not* to be used by any package outside of the commands package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetTranslationFunc

func GetTranslationFunc(config Config) (i18n.TranslateFunc, error)

GetTranslationFunc will return back a function that can be used to translate strings into the currently set locale.

Types

type Config

type Config interface {
	// ColorEnabled enables or disabled color
	ColorEnabled() configv3.ColorSetting
	// Locale is the language to translate the output to
	Locale() string
}

Config is the UI configuration

type TranslatableError

type TranslatableError interface {
	// Returns back the untranslated error string
	Error() string
	Translate(func(string, ...interface{}) string) string
}

TranslatableError it wraps the error interface adding a way to set the translation function on the error

type UI

type UI struct {
	// In is the input buffer
	In io.Reader
	// Out is the output buffer
	Out io.Writer
	// Err is the error buffer
	Err io.Writer
	// contains filtered or unexported fields
}

UI is interface to interact with the user

func NewTestUI

func NewTestUI(in io.Reader, out io.Writer, err io.Writer) *UI

NewTestUI will return a UI object where Out, In, and Err are customizable, and colors are disabled

func NewUI

func NewUI(c Config) (*UI, error)

NewUI will return a UI object where Out is set to STDOUT, In is set to STDIN, and Err is set to STDERR

func (*UI) DisplayBoolPrompt

func (ui *UI) DisplayBoolPrompt(prompt string, defaultResponse bool) (bool, error)

DisplayBoolPrompt outputs the prompt and waits for user input. It only allows for a boolean response. A default boolean response can be set with defaultResponse.

func (*UI) DisplayError

func (ui *UI) DisplayError(err error)

DisplayError outputs the translated error message to ui.Err if the error satisfies TranslatableError, otherwise it outputs the original error message to ui.Err. It also outputs "FAILED" in bold red to ui.Out.

func (*UI) DisplayHeader

func (ui *UI) DisplayHeader(text string)

DisplayHeader translates the header, bolds and adds the default color to the header, and outputs the result to ui.Out.

func (*UI) DisplayNewline

func (ui *UI) DisplayNewline()

DisplayNewline outputs a newline to UI.Out.

func (*UI) DisplayOK

func (ui *UI) DisplayOK()

DisplayOK outputs a bold green translated "OK" to UI.Out.

func (*UI) DisplayPair

func (ui *UI) DisplayPair(attribute string, template string, templateValues ...map[string]interface{})

DisplayPair translates the attribute, translates the template, substitutes templateValues into the template, and outputs the pair to ui.Out. Only the first map in templateValues is used.

func (*UI) DisplayTable

func (ui *UI) DisplayTable(prefix string, table [][]string, padding int) error

DisplayTable outputs a matrix of strings as a table to UI.Out. Prefix will be prepended to each row and padding adds the specified number of spaces between columns.

func (*UI) DisplayText

func (ui *UI) DisplayText(template string, templateValues ...map[string]interface{})

DisplayText translates the template, substitutes in templateValues, and outputs the result to ui.Out. Only the first map in templateValues is used.

func (*UI) DisplayTextWithFlavor

func (ui *UI) DisplayTextWithFlavor(template string, templateValues ...map[string]interface{})

DisplayTextWithFlavor translates the template, bolds and adds cyan color to templateValues, substitutes templateValues into the template, and outputs the result to ui.Out. Only the first map in templateValues is used.

func (*UI) DisplayWarning

func (ui *UI) DisplayWarning(template string, templateValues ...map[string]interface{})

DisplayWarning translates the warning, substitutes in templateValues, and outputs to ui.Err. Only the first map in templateValues is used.

func (*UI) DisplayWarnings

func (ui *UI) DisplayWarnings(warnings []string)

DisplayWarnings translates the warnings and outputs to ui.Err.

func (*UI) TranslateText

func (ui *UI) TranslateText(template string, templateValues ...map[string]interface{}) string

TranslateText passes the template through an internationalization function to translate it to a pre-configured language, and returns the template with templateValues substituted in. Only the first map in templateValues is used.

Directories

Path Synopsis
This file was generated by counterfeiter
This file was generated by counterfeiter

Jump to

Keyboard shortcuts

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