Documentation
¶
Overview ¶
Package ui carries the CLI's output conventions: the [error] / [warn] / [debug] prefixes of the bash implementation's verbose.sh, byte for byte off a terminal so ported commands stay indistinguishable from their argsh originals, and the terminal presentation layer (style.go) on top.
Index ¶
- Variables
- func Closest(name string, candidates []string) (best string, ok bool)
- func Debug(format string, a ...any)
- func DebugTo(w io.Writer, format string, a ...any)
- func Error(format string, a ...any)
- func ErrorNext(w io.Writer, cmd, why, format string, a ...any)
- func ErrorTo(w io.Writer, format string, a ...any)
- func ForceColor(on bool) (restore func())
- func ForceTTY(on bool) (restore func())
- func Handled(err error) error
- func HuhTheme() huh.Theme
- func MarkBad(w io.Writer, msg string)
- func MarkInfo(w io.Writer, msg string)
- func MarkOK(w io.Writer, msg string)
- func MarkWarn(w io.Writer, msg string)
- func Next(w io.Writer, cmd, why string)
- func NoticeTo(w io.Writer, format string, a ...any)
- func Quiet() bool
- func RawErrorTo(w io.Writer, format string, a ...any)
- func RawWarningTo(w io.Writer, format string, a ...any)
- func Section(w io.Writer, label string)
- func SetNoColor(on bool)
- func SetQuiet(q bool)
- func StdinIsTerminal() bool
- func Styled(w io.Writer, s Style) io.Writer
- func Table(w io.Writer, header []string, rows [][]string, minWidths []int)
- func Title(w io.Writer, text string)
- func Warn(format string, a ...any)
- func WarnTo(w io.Writer, format string, a ...any)
- type Columns
- type Style
- type Styler
Constants ¶
This section is empty.
Variables ¶
var ErrHandled = errors.New("handled")
ErrHandled marks an error whose message was already printed in the bash implementation's own format ([error] … on stderr). It is the ONE sentinel: every package's name for it (cli.ErrHandled, kubehz.ErrHandled, secrets.ErrHandled, …) is this value, so errors.Is holds across package boundaries and a %w wrap anywhere still reads as handled. The caller exits non-zero without printing anything further.
Functions ¶
func Closest ¶ added in v0.5.0
Closest is the candidate nearest to name by cobra's rule: an edit distance of at most 2, or a candidate that starts with name. The first (in candidates' order) of the nearest wins. ok is false when nothing qualifies.
func ErrorNext ¶ added in v0.5.0
ErrorNext writes the error for w. On a terminal (the style of w, see For) the two-line shape prints: the `error:` line, then the Next line for cmd (without `lo`) and why. Otherwise the [error] line prints, byte for byte what ErrorTo prints. An empty cmd prints no second line.
func ForceColor ¶ added in v0.5.0
func ForceColor(on bool) (restore func())
ForceColor is a test-only override of the colour decision. It applies only where TTY is true: ForceColor(true) with ForceTTY(true) renders the coloured terminal form into a buffer, ForceColor(false) keeps a forced terminal plain. Off a terminal the output stays plain whatever the override says. Production code never calls it.
func ForceTTY ¶ added in v0.5.0
func ForceTTY(on bool) (restore func())
ForceTTY is a test-only override of the terminal detection: every writer resolves as a terminal (true) or as a pipe (false), so a bytes.Buffer renders the terminal form under go test without a pty. The returned function restores the previous state. Production code never calls it.
func Handled ¶
Handled marks err as already printed: the returned error reads as ErrHandled to errors.Is, keeps err's text, and unwraps to err so any sentinel or type inside it still matches. A site that prints its own [error] line and then returns an error wraps it here, and the exit mapping at the top (cli dispatchExit) prints nothing more. An error that reaches the top WITHOUT this mark was never printed, so the mapping prints it. nil stays nil.
func HuhTheme ¶ added in v0.5.0
HuhTheme is the one huh theme of the CLI: base16 (the terminal's own palette) with the accent on the doctor green: the title, the selector and the selected option. The init wizard and the `lo use` select share it.
func MarkInfo ¶ added in v0.5.0
MarkInfo writes ` ℹ msg`, a neutral fact that is neither a pass nor a finding. The whole line is dim on a TTY (the style the lifecycle commands use for their notes).
func NoticeTo ¶ added in v0.5.0
NoticeTo writes an informational line to w, or nothing under --quiet.
func RawErrorTo ¶ added in v0.5.0
RawErrorTo writes the raw `error: …` line the bash `echo "error: …" >&2` family prints (no [error] prefix). The word is red on a TTY.
func RawWarningTo ¶ added in v0.5.0
RawWarningTo writes the raw `warning: …` line. The word is yellow on a TTY.
func Section ¶ added in v0.5.0
Section writes a section header: `--- label ---` piped, the bold label on a TTY.
func SetNoColor ¶ added in v0.5.0
func SetNoColor(on bool)
SetNoColor records the global --no-color flag (the env form is NO_COLOR). It also exports NO_COLOR=1 so every child (the provider plugins, a routed bash command) sees the same choice.
func SetQuiet ¶ added in v0.5.0
func SetQuiet(q bool)
SetQuiet sets the quiet level for the process.
func StdinIsTerminal ¶ added in v0.5.0
func StdinIsTerminal() bool
StdinIsTerminal reports whether stdin is a terminal (a prompt or a select needs both stdin and stdout on one).
func Styled ¶ added in v0.5.0
Styled wraps w with a fixed style. For honours the whole style: a Styled(w, Style{TTY: true, Color: false}) writer never carries colour, whatever the overrides say.
func Table ¶ added in v0.5.0
Table writes header, its underline and rows, columns two spaces apart (NewColumns for the width rules).
Types ¶
type Columns ¶ added in v0.5.0
type Columns struct {
// contains filtered or unexported fields
}
Columns is a table in progress: the header and the measured widths, so a caller can interleave its own lines between rows (the assets diff prints the per-file rows under each unit). Table is the one-call form.
func NewColumns ¶ added in v0.5.0
NewColumns measures the columns of header over rows. minWidths are the minimum column widths (nil, or 0 for a column: none). Piped, a column with a minimum is exactly that wide, and a cell that is wider pushes only its own row (bash printf `%-20s` semantics), so the bytes match the fixed layouts of the ported commands. On a TTY every column is measured (never narrower than its minimum), so nothing overflows.
type Style ¶ added in v0.5.0
type Style struct {
// TTY is true when the stream is a terminal: titles and sections drop
// their === / --- decoration, tables are measured, hints are dimmed.
TTY bool
// Color is true when ANSI colour is allowed: a TTY, and neither
// NO_COLOR nor --no-color is set. Never true off a TTY.
Color bool
}
Style is what a stream can show.
func For ¶ added in v0.5.0
For is the style of w: a Styled wrapper's own (its Color gated by NO_COLOR and --no-color like every stream), the process stdout's or stderr's for those files, plain for anything else (a buffer, a pipe, a file). Under the test overrides every other writer gets the forced style.
func (Style) Bold ¶ added in v0.5.0
Bold and Dim are the two weights of the palette; Warn is the `!` colour for a marker inside a row the caller lays out itself (the card of `lo init`; MarkWarn writes a whole line).