Documentation
¶
Overview ¶
Package ui is how mcloud talks to you: colors, spinners, tables and prompts on a terminal, and plain lines everywhere else (pipes, CI, NO_COLOR, TERM=dumb, --plain), so logs and scripts read as before.
Decoration goes to the error stream; what a command produces for pipes (an image, a URL, names) stays on the output stream.
Index ¶
- Variables
- type Option
- type Step
- type UI
- func (u *UI) Accent(s string) string
- func (u *UI) Amber(s string) string
- func (u *UI) Bold(s string) string
- func (u *UI) Box(title string, rows [][2]string)
- func (u *UI) Confirm(question string) (bool, error)
- func (u *UI) Dim(s string) string
- func (u *UI) Error(err error)
- func (u *UI) Fancy() bool
- func (u *UI) Green(s string) string
- func (u *UI) Heading(s string)
- func (u *UI) Hint(format string, a ...any)
- func (u *UI) Input(title, def string, validate func(string) error) (string, error)
- func (u *UI) KV(pairs [][2]string)
- func (u *UI) Link(url string) string
- func (u *UI) Mark(status string, exists bool) string
- func (u *UI) Note(format string, a ...any)
- func (u *UI) Printf(format string, a ...any)
- func (u *UI) Println(a ...any)
- func (u *UI) Red(s string) string
- func (u *UI) Secret(prompt string) (string, error)
- func (u *UI) Select(title string, options []Option, def string) (string, error)
- func (u *UI) Step(title string) *Step
- func (u *UI) StepTail(title string, n int) *Step
- func (u *UI) Success(format string, a ...any)
- func (u *UI) Table(headers []string, rows [][]string)
- func (u *UI) TypeToConfirm(prompt, want string) (bool, error)
- func (u *UI) Warn(format string, a ...any)
Constants ¶
This section is empty.
Variables ¶
var ErrAborted = errors.New("aborted")
ErrAborted: you said no, or left a prompt.
var ErrNoTerminal = errors.New("not a terminal: pass --yes to go ahead")
ErrNoTerminal: a question needs a terminal to be asked on.
Functions ¶
This section is empty.
Types ¶
type Step ¶
type Step struct {
// contains filtered or unexported fields
}
Step is one stage of a longer command. On a terminal it's a spinner with the time so far, a status after its title, and (with a tail) the last lines of what it's running, which disappear when it's done; it ends as "✓ title 12s" or "✗ title". Plain, it's "title ...", its status and log lines indented, and " done (12s)".
func (*Step) Log ¶
Log is a line of output under the step: kept in its tail on a terminal (or printed above it, quietly, if it has none), printed indented plain.
type UI ¶
type UI struct {
In io.Reader
Out io.Writer
Err io.Writer
// contains filtered or unexported fields
}
UI writes to Out (results) and Err (progress, notes), and reads In.
func New ¶
New decides once whether to be fancy: both streams are terminals, and nothing asks for plain output.
func (*UI) Error ¶
Error shows a command's error: its first line in red, the rest quiet (plain: "mcloud: ..." as always).
func (*UI) Mark ¶
Mark is a one-character summary of a condition's status: True, False, anything else (waiting), or - when there's no such thing.
func (*UI) StepTail ¶
StepTail starts a step that shows the last n lines it's given (Log, or Writer) while it runs.
func (*UI) TypeToConfirm ¶
TypeToConfirm makes you type want.