Documentation ¶
Overview ¶
Package terminal is used by plugins to read and write to a terminal UI. The abstractions presented in this package are meant to be portable across a variety of styles that may be presented to the user and enables plugins to focus on their core logic.
The primary interface to look at is UI.
Index ¶
Constants ¶
const ( Yellow = "yellow" Green = "green" Red = "red" )
Color constants
const ( HeaderStyle = "header" ErrorStyle = "error" WarningStyle = "warning" InfoStyle = "info" SuccessStyle = "success" SuccessBoldStyle = "success-bold" )
Style constants
Variables ¶
This section is empty.
Functions ¶
Types ¶
type NamedValue ¶
type NamedValue struct { Value interface{} Name string }
NamedValue provides a nicely formatted key: value output
type Option ¶
type Option func(*config)
Option controls output styling.
func WithErrorStyle ¶
func WithErrorStyle() Option
WithErrorStyle styles the output as an error message.
func WithHeaderStyle ¶
func WithHeaderStyle() Option
WithHeaderStyle styles the output like a header denoting a new section of execution. This should only be used with single-line output. Multi-line output will not look correct.
func WithInfoStyle ¶
func WithInfoStyle() Option
WithInfoStyle styles the output like it's formatted information.
func WithSuccessBoldStyle ¶
func WithSuccessBoldStyle() Option
WithSuccessBoldStyle styles the output as a success message.
func WithSuccessStyle ¶
func WithSuccessStyle() Option
WithSuccessStyle styles the output as a success message.
func WithWarningStyle ¶
func WithWarningStyle() Option
WithWarningStyle styles the output as an error message.
type Table ¶
type Table struct { Headers []string Rows [][]TableEntry }
Table provides a nicely formatted table.
type TableEntry ¶
TableEntry is a single entry for a table.
type UI ¶
type UI interface { // Output outputs a message directly to the terminal. The remaining // arguments should be interpolations for the format string. After the // interpolations you may add Options. Output(string, ...interface{}) // Output data as a table of data. Each entry is a row which will be output // with the columns lined up nicely. NamedValues([]NamedValue, ...Option) // OutputWriters returns stdout and stderr writers. These are usually // but not always TTYs. This is useful for subprocesses, network requests, // etc. Note that writing to these is not thread-safe by default so // you must take care that there is only ever one writer. OutputWriter() (io.WriteCloser, error) // Table outputs the information formatted into a Table structure. Table(*Table, ...Option) }
UI is the primary interface for interacting with a user via the CLI.
Some of the methods on this interface return values that have a lifetime such as Status and StepGroup. While these are still active (haven't called the close or equivalent method on these values), no other method on the UI should be called.