Version: v0.0.0-...-b817d9f Latest Latest

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

Go to latest
Published: Sep 28, 2015 License: MPL-2.0 Imports: 5 Imported by: 0




This section is empty.


This section is empty.


func Colorize

func Colorize(t string) string

Colorize is a helper to colorize the string according to the colorstring library defaults.

func StripColors

func StripColors(t string) string

StripColors is a helper to strip all the color tags from the text.


type InputOpts

type InputOpts struct {
	// Id is a unique ID for the question being asked that might be
	// used for logging or to look up a prior answered question.
	Id string

	// Query is a human-friendly question for inputting this value.
	Query string

	// Description is a description about what this option is. Be wary
	// that this will probably be in a terminal so split lines as you see
	// necessary.
	Description string

	// Default will be the value returned if no data is entered.
	Default string

	// Hide will hide the text while it is being typed.
	Hide bool

	// EnvVars is a list of environment variables where the value can be looked
	// up, in priority order. If any of these environment Variables are
	// non-empty, they will be returned as the value for this input and the user
	// will not be prompted.
	EnvVars []string

InputOpts are options for asking for input.

func (*InputOpts) EnvVarValue

func (o *InputOpts) EnvVarValue() string

EnvVarValue reads the configured list of EnvVars, returns the first non-empty value it finds, otherwise returns an empty string.

type Mock

type Mock struct {
	HeaderBuf  []string
	MessageBuf []string
	RawBuf     []string

	InputResult string
	InputError  error

Mock is an implementation of Ui that stores its data in-memory primarily for testing purposes.

func (*Mock) Header

func (u *Mock) Header(msg string)

func (*Mock) Input

func (u *Mock) Input(opts *InputOpts) (string, error)

func (*Mock) Message

func (u *Mock) Message(msg string)

func (*Mock) Raw

func (u *Mock) Raw(msg string)

type Styled

type Styled struct {

Styled is a wrapper around an existing UI that automatically adds formatting around the UI text.

func (*Styled) Header

func (u *Styled) Header(msg string)

func (*Styled) Message

func (u *Styled) Message(msg string)

type Ui

type Ui interface {
	// Header, Message, and Raw are all methods for outputting messages
	// to the Ui, all with different styles. Header and Message should
	// be used liberally, and Raw should be scarcely used if possible.
	// Header outputs the message with a style denoting it is a sectional
	// message. An example: "==> TEXT" might be header text.
	// Message outputs the message with a style, but one that is less
	// important looking than Header. Example: "    TEXT" might be
	// the message text, prefixed with spaces so that it lines up with
	// header items.
	// Raw outputs a message with no styling.

	// Input is used to ask the user for input. This should be done
	// sparingly or very early on since Otto is meant to be an automated
	// tool.
	Input(*InputOpts) (string, error)

Ui is the component of Otto responsible for reading/writing to the console.

All Ui implementations MUST expect colorstring[1] style inputs. If the output interface doesn't support colors, these must be stripped. The StripColors helper in this package can be used to do this. For terminals, the Colorize helper in this package can be used.

[1]: github.com/mitchellh/colorstring

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL