ui

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: MIT Imports: 13 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

Constants

This section is empty.

Variables

View Source
var ErrAborted = errors.New("aborted")

ErrAborted: you said no, or left a prompt.

View Source
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 Option

type Option struct{ Label, Value string }

Option is one choice for Select.

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) Done

func (s *Step) Done(format string, a ...any)

Done ends the step well; msg (optional) replaces its title.

func (*Step) Fail

func (s *Step) Fail(format string, a ...any)

Fail ends the step badly; the last lines of its output stay on screen.

func (*Step) Log

func (s *Step) Log(line string)

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.

func (*Step) Skip

func (s *Step) Skip(format string, a ...any)

Skip ends the step as not needed.

func (*Step) Status

func (s *Step) Status(format string, a ...any)

Status shows what the step is at, after its title (plain: a line when it changes).

func (*Step) Writer

func (s *Step) Writer() io.Writer

Writer is an io.Writer whose lines go to Log (carriage returns too, as progress bars use them).

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

func New(in io.Reader, out, err io.Writer, plain bool) *UI

New decides once whether to be fancy: both streams are terminals, and nothing asks for plain output.

func (*UI) Accent

func (u *UI) Accent(s string) string

func (*UI) Amber

func (u *UI) Amber(s string) string

func (*UI) Bold

func (u *UI) Bold(s string) string

func (*UI) Box

func (u *UI) Box(title string, rows [][2]string)

Box is a framed panel with a title and aligned rows (plain: the rows).

func (*UI) Confirm

func (u *UI) Confirm(question string) (bool, error)

Confirm asks a yes/no question; no is the default.

func (*UI) Dim

func (u *UI) Dim(s string) string

func (*UI) Error

func (u *UI) Error(err error)

Error shows a command's error: its first line in red, the rest quiet (plain: "mcloud: ..." as always).

func (*UI) Fancy

func (u *UI) Fancy() bool

Fancy reports whether colors and spinners are on.

func (*UI) Green

func (u *UI) Green(s string) string

func (*UI) Heading

func (u *UI) Heading(s string)

Heading is a section title.

func (*UI) Hint

func (u *UI) Hint(format string, a ...any)

Hint is an indented, quiet line under what came before.

func (*UI) Input

func (u *UI) Input(title, def string, validate func(string) error) (string, error)

Input asks for text; def is filled in.

func (*UI) KV

func (u *UI) KV(pairs [][2]string)

KV prints aligned "key value" lines.

func (u *UI) Link(url string) string

Link is a URL, clickable in terminals that know OSC 8.

func (*UI) Mark

func (u *UI) Mark(status string, exists bool) string

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) Note

func (u *UI) Note(format string, a ...any)

Note is good to know: "· ..." (plain: "note: ...").

func (*UI) Printf

func (u *UI) Printf(format string, a ...any)

Printf writes a line to Out.

func (*UI) Println

func (u *UI) Println(a ...any)

Println writes lines to Out.

func (*UI) Red

func (u *UI) Red(s string) string

func (*UI) Secret

func (u *UI) Secret(prompt string) (string, error)

Secret asks for a value without showing it.

func (*UI) Select

func (u *UI) Select(title string, options []Option, def string) (string, error)

Select asks to pick one; def is preselected.

func (*UI) Step

func (u *UI) Step(title string) *Step

Step starts a step that shows no output of its own.

func (*UI) StepTail

func (u *UI) StepTail(title string, n int) *Step

StepTail starts a step that shows the last n lines it's given (Log, or Writer) while it runs.

func (*UI) Success

func (u *UI) Success(format string, a ...any)

Success is a done thing: "✓ ...".

func (*UI) Table

func (u *UI) Table(headers []string, rows [][]string)

Table prints rows in aligned columns under a header; cells may hold colors.

func (*UI) TypeToConfirm

func (u *UI) TypeToConfirm(prompt, want string) (bool, error)

TypeToConfirm makes you type want.

func (*UI) Warn

func (u *UI) Warn(format string, a ...any)

Warn is something to look at: "! ..." (plain: "warning: ...").

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL