ui

package
v0.20.1 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package ui is the CLI's presentation layer: TTY-aware color, status glyphs, aligned tables, relative timestamps, a spinner, and confirmation prompts. Everything degrades cleanly when output is not a terminal (pipes, CI) or when color is disabled via NO_COLOR / --no-color, so machine consumers get plain text and humans get a polished terminal experience.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Age

func Age(t time.Time) string

Age renders t as a short, human relative age ("just now", "5m", "3h", "2d").

func Bold

func Bold(s string) string

Text-styling helpers — no-ops when color is disabled.

func Confirm

func Confirm(prompt string) bool

Confirm asks a yes/no question on stderr and reads the answer from stdin. A non-interactive stdin (no TTY) returns false — callers must pass --yes.

func Cyan

func Cyan(s string) string

func Detail

func Detail(format string, a ...any)

Detail prints a plain line to stdout with no leading glyph. Use it for resource-detail views (aligned "Field: value" blocks) where the arrow Info prepends would be visual noise; keep Info for progress and next-step hints.

func Dim

func Dim(s string) string

func Fail

func Fail(format string, a ...any)

Fail prints a red cross line to stderr.

func Green

func Green(s string) string

func Info

func Info(format string, a ...any)

Info prints a cyan arrow line to stdout (progress / neutral status).

func IsTerminal

func IsTerminal() bool

IsTerminal reports whether stdout is an interactive terminal (a character device), using only the standard library.

func Magenta

func Magenta(s string) string

func Red

func Red(s string) string

func SetColor

func SetColor(on bool)

SetColor force-enables or disables color, overriding auto-detection. The root command calls this for --no-color and structured (--json/-o) output. Color is only ever honored on a TTY, so passing true off a pipe stays plain.

func Status

func Status(s string) string

Status returns the status string colored by outcome: green for success, red for failure, yellow for anything in-progress/pending.

func Success

func Success(format string, a ...any)

Success prints a green check line to stdout.

func Warn

func Warn(format string, a ...any)

Warn prints a yellow bang line to stderr.

func Yellow

func Yellow(s string) string

Types

type Spinner

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

Spinner is a lightweight terminal spinner for long-running waits. On a non-terminal (pipe/CI) it degrades to nothing — the caller's plain status lines carry the information instead.

func NewSpinner

func NewSpinner(msg string) *Spinner

NewSpinner creates a spinner with an initial message (not yet started).

func (*Spinner) Start

func (s *Spinner) Start()

Start begins animating on stderr. No-op off a TTY.

func (*Spinner) Stop

func (s *Spinner) Stop()

Stop halts the animation and clears the line. Safe to call more than once.

func (*Spinner) Update

func (s *Spinner) Update(msg string)

Update changes the spinner's message in place.

type Table

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

Table is a minimal column-aligned table with a dimmed header row.

func NewTable

func NewTable(headers ...string) *Table

NewTable starts a table with the given (uppercased) column headers.

func (*Table) Print

func (t *Table) Print()

Print renders the table to stdout.

func (*Table) Render

func (t *Table) Render(w io.Writer)

Render writes the aligned table to w. Column widths are measured by on-screen width — ANSI color codes and multi-byte runes are counted as they render, not by raw byte length

func (*Table) Row

func (t *Table) Row(cells ...any)

Row appends one row; cells are formatted with %v and padded to the header count.

Jump to

Keyboard shortcuts

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