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 ¶
- func GetTranslationFunc(config Config) (i18n.TranslateFunc, error)
- type Config
- type TranslatableError
- type UI
- func (ui *UI) DisplayBoolPrompt(prompt string, defaultResponse bool) (bool, error)
- func (ui *UI) DisplayError(err TranslatableError)
- func (ui *UI) DisplayErrorMessage(err string, keys ...map[string]interface{})
- func (ui *UI) DisplayHeaderFlavorText(formattedString string, keys ...map[string]interface{})
- func (ui *UI) DisplayHelpHeader(text string)
- func (ui *UI) DisplayNewline()
- func (ui *UI) DisplayOK()
- func (ui *UI) DisplayPair(attribute string, formattedString string, keys ...map[string]interface{})
- func (ui *UI) DisplayTable(prefix string, table [][]string)
- func (ui *UI) DisplayText(formattedString string, keys ...map[string]interface{})
- func (ui *UI) DisplayTextWithKeyTranslations(formattedString string, keysToTranslate []string, ...)
- func (ui *UI) DisplayWarning(formattedString string, keys ...map[string]interface{})
- func (ui *UI) DisplayWarnings(warnings []string)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetTranslationFunc ¶
func GetTranslationFunc(config Config) (i18n.TranslateFunc, error)
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 ¶
NewTestUI will return a UI object where Out, In, and Err are customizable, and colors are disabled
func NewUI ¶
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 ¶
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 TranslatableError)
DisplayError outputs the error to UI.Err and outputs a red translated "FAILED" to UI.Out.
func (*UI) DisplayErrorMessage ¶
DisplayErrorMessage combines the err template with the key maps and then outputs it to the UI.Err file. It will then output a red translated "FAILED" to UI.Out. Prior to outputting the err, it is run through an internationalization function to translate it to a pre-configured language.
func (*UI) DisplayHeaderFlavorText ¶
DisplayHeaderFlavorText outputs the translated text, with cyan color keys, to UI.Out.
func (*UI) DisplayHelpHeader ¶
DisplayHelpHeader translates and then bolds the help header. Sends output 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 green translated "OK" message to UI.Out.
func (*UI) DisplayPair ¶
DisplayPair outputs the "attribute: formattedString" pair to UI.Out. keys are applied to the translation of formattedString, while attribute is translated directly.
func (*UI) DisplayTable ¶
DisplayTable presents a two dimensional array of strings as a table to UI.Out
func (*UI) DisplayText ¶
DisplayText combines the formattedString template with the key maps and then outputs it to the UI.Out file. Prior to outputting the formattedString, it is run through an internationalization function to translate it to a pre-configured language. Only the first map in keys is used.
func (*UI) DisplayTextWithKeyTranslations ¶
func (ui *UI) DisplayTextWithKeyTranslations(formattedString string, keysToTranslate []string, keys ...map[string]interface{})
DisplayTextWithKeyTranslations translates the keys listed in keysToTranslate, and then passes these values to DisplayText. Only the first map in keys is used.
func (*UI) DisplayWarning ¶
DisplayWarning applies translation to formattedString and displays the translated warning to UI.Err.
func (*UI) DisplayWarnings ¶
DisplayWarnings translates and displays the warnings.