Documentation ¶
Overview ¶
package ui contains functionality for prompting for input, colorizing output, and creating animations.
Index ¶
- Variables
- func Attached() bool
- type Call
- type Details
- type Mock
- func (m *Mock) Confirm(question string) error
- func (m *Mock) Details(details Details) error
- func (m *Mock) Notify(t NotificationType, msg string, args ...interface{}) error
- func (m *Mock) Question(question string, validator promptui.ValidateFunc) (string, error)
- func (m *Mock) Secret(question string, validator promptui.ValidateFunc) (string, error)
- func (m *Mock) Table(header TableHeader, body TableBody) error
- func (m *Mock) Template(t string, args interface{}) error
- type NotificationType
- type Stdout
- func (u *Stdout) CanColorize() bool
- func (u *Stdout) Confirm(question string) error
- func (u *Stdout) Details(details Details) error
- func (u *Stdout) Notify(t NotificationType, msg string, args ...interface{}) error
- func (u *Stdout) Question(question string, validator promptui.ValidateFunc) (string, error)
- func (u *Stdout) Secret(question string, validator promptui.ValidateFunc) (string, error)
- func (u *Stdout) Table(header TableHeader, body TableBody) error
- func (u *Stdout) Template(t string, args interface{}) error
- type TableBody
- type TableHeader
- type UI
Constants ¶
This section is empty.
Variables ¶
var ( // AbortedCause represents types of errors where the user aborted the operation AbortedCause = errors.NewCause(errors.BadRequestCategory, "user_aborted") // NotAttachedCause represents types of errors that are caused when a ui // element is attempted to be used that are not supported by the terminal NotAttachedCause = errors.NewCause(errors.BadRequestCategory, "not_attached") // CannotDisplayCause represents types of errors that are caused when a // provided value cannot be displayed by a ui component CannotDisplayCause = errors.NewCause(errors.BadRequestCategory, "cannot_display") // ErrAborted is an error when a user aborts while filling out a prompt ErrAborted = errors.New(AbortedCause, "Aborted") // ErrCantDisplay happens when a value is given to a UI Component that // cannot be displayed (e.g. isn't a string or doesn't have a String() // method) ErrCantDisplay = errors.New(CannotDisplayCause, "Cannot display value, expected a string or fmt.Stringer") )
var ( // Warn represents a warning notification to the user Warn = NotificationType{ Symbol: "⚠", Text: "Warning", Color: ansiterm.Yellow, } // Error represents an error notification to the user Error = NotificationType{ Symbol: "✗", Text: "Error", Color: ansiterm.Red, } // Remember represents a reminder notification to the user Remember = NotificationType{ Symbol: "‼", Text: "Remember", Color: ansiterm.Green, } )
Functions ¶
Types ¶
type Call ¶
type Call struct { Name string Args []interface{} }
Call is a helper struct to record types of calls
type Details ¶
type Details map[string]interface{}
Details is used to colorize a series of key and value pairs when listing colors in the Stdout
type Mock ¶
type Mock struct {
Calls []*Call
}
Mock is a fake UI that will track what it was called with
func (*Mock) Notify ¶
func (m *Mock) Notify(t NotificationType, msg string, args ...interface{}) error
Notify from the UI interface
type NotificationType ¶
NotificationType represents a type of notification such as a warning or error
type Stdout ¶
Stdout is an implementation of UI that prints to stdout while taking into account the state of a users terminal.
func (*Stdout) CanColorize ¶
CanColorized returns whether or not colorization can be supported
func (*Stdout) Confirm ¶
Confirm prompts the user with a confirmation dialog
Confirmation dialogs are usually used to ask the user if they really want to perform an action. If stdout is not attached to a terminal then an error is returned.
func (*Stdout) Details ¶
Details prints the provided details to the Stdout. Details is a Stdout Component with labelled key and value pairs.
func (*Stdout) Notify ¶
func (u *Stdout) Notify(t NotificationType, msg string, args ...interface{}) error
Notify is used to notify the user about some piece of information including error messages or warning.
type TableBody ¶
type TableBody [][]string
TableBody is used with the `Table` function. It is a slice of string slices that contain the body of your table. E.g. [
[ "Ben", "100", "jdkslajdklas" ], [ "Ian", "100", "jdklsajdklsa" ], [ "Justin", "100", "kljdaslkdaskjl" ],
]
type TableHeader ¶
type TableHeader []string
TableHeader is used with the `Table` function. It will print the header of your table in bold. E.g. [ "Name", "Number", "Gibberish" ]
type UI ¶
type UI interface { Notify(t NotificationType, msg string, args ...interface{}) error Secret(question string, validator promptui.ValidateFunc) (string, error) Question(question string, validator promptui.ValidateFunc) (string, error) Confirm(question string) error Table(header TableHeader, body TableBody) error Template(t string, args interface{}) error Details(details Details) error }
UI makes it easy to present prompts, animation, and other ui enhancements