ui

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2026 License: MIT Imports: 11 Imported by: 3 modules, 1 package

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 provides shared terminal output helpers for the adaouat CLIs: color/TTY detection, status lines, and version/help banner renderers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Err

func Err(w io.Writer, msg string) string

Err returns "✗ <msg>" styled red when w supports color, plain otherwise.

func HasColor

func HasColor(w io.Writer) bool

HasColor reports whether w supports ANSI color output. It delegates to colorprofile.Detect, which honours NO_COLOR, CLICOLOR_FORCE, TERM=dumb, and whether w is a terminal.

func Header(w io.Writer, title string)

Header writes a bold section title to w, surrounded by blank lines.

func HelpLong

func HelpLong(art, catchPhrase string) string

HelpLong returns ASCII art followed by a catch-phrase, for use as cobra root.Long. Apps pass their own art and tagline.

func Info

func Info(w io.Writer, msg string) string

Info returns " <msg>" dimmed when w supports color, plain otherwise. Use for hints and supplementary context below a primary status line.

func IsTTY

func IsTTY(w io.Writer) bool

IsTTY reports whether w is a terminal.

func Skip

func Skip(detail string) error

Skip marks a task as advisory: Spinner.Run renders "! name — detail" instead of success or failure and returns nil.

func Success

func Success(w io.Writer, msg string) string

Success returns "✓ <msg>" styled green when w supports color, plain otherwise.

func VersionTemplate

func VersionTemplate(art, catchPhrase string) string

VersionTemplate returns a cobra text/template string for --version output. cobra fills {{.Name}} and {{.Version}} at runtime.

func Warn

func Warn(w io.Writer, msg string) string

Warn returns "! <msg>" styled yellow when w supports color, plain otherwise. Use for skipped checks and non-critical notices.

Types

type Mode

type Mode int

Mode is a CLI's output mode. Spinners, progress bars, and colors are only shown in Human mode on a real TTY. The zero value is Human.

const (
	Human Mode = iota // styled, interactive output for a human at a TTY
	Plain             // unstyled plain text, for CI and pipes
	JSON              // newline-delimited JSON events
)

func ParseMode

func ParseMode(s string) Mode

ParseMode maps a flag value to a Mode, defaulting to Human for unknown input.

func (Mode) IsHuman

func (m Mode) IsHuman() bool

IsHuman reports whether m is the human (styled) output mode.

func (Mode) String

func (m Mode) String() string

String returns the mode's flag name.

type Result

type Result struct {
	Detail string
	Subs   []string
}

Result is a task's successful outcome: a Detail shown after the task name ("✓ name — Detail") and optional indented sub-result lines.

type Spinner

type Spinner struct {
	// contains filtered or unexported fields
}

Spinner runs named tasks, animating a spinner while each runs (human mode on a TTY) and resolving it to a ✓/✗/! status line written to out.

func NewSpinner

func NewSpinner(out io.Writer, m Mode) *Spinner

NewSpinner constructs a Spinner writing to out, animating only in m's human mode.

func (*Spinner) Run

func (s *Spinner) Run(name string, fn func() (Result, error)) error

func (*Spinner) Step

func (s *Spinner) Step(name, detail string)

Step renders a numbered "✓ N/total name — detail" line for a step whose work already completed successfully, advancing the counter. Use it for steps whose work ran outside the spinner; use Run when the work should animate.

func (*Spinner) Total

func (s *Spinner) Total(total int) *Spinner

Total enables an N/total counter prefix on each task line.

Jump to

Keyboard shortcuts

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