ux

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: May 12, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package ux owns the CLI's rich-output primitives: palette, spinner, progress driver for long-running polls. All exported entry points respect the IOStreams ColorEnabled / SpinnersEnabled flags, falling back to plain stderr output when the environment (CI, NO_COLOR, pipe) doesn't support ANSI.

Index

Constants

This section is empty.

Variables

View Source
var DefaultPalette = Palette{
	Success: lipgloss.NewStyle().Foreground(lipgloss.ANSIColor(10)),
	Warn:    lipgloss.NewStyle().Foreground(lipgloss.ANSIColor(11)),
	Error:   lipgloss.NewStyle().Foreground(lipgloss.ANSIColor(9)),
	Dim:     lipgloss.NewStyle().Faint(true),
}

DefaultPalette: ANSI bright green / yellow / red + ANSI faint for dim. lipgloss honours NO_COLOR and non-TTY streams automatically via its detected-profile heuristic, but we also gate every caller by IOStreams.ColorEnabled for belt-and-braces consistency.

View Source
var ErrWaitTimeout = errors.New("wait timeout exceeded")

ErrWaitTimeout is returned when a WaitFor run exceeds its timeout. Commands translate this into cli.TimeoutError with exit code 8.

Functions

func ColorPhase

func ColorPhase(phase string, colorEnabled bool) string

ColorPhase returns phase either styled or plain, chosen by the caller's ColorEnabled flag. Exported so the cluster table printer stays cheap and doesn't need to know about lipgloss directly.

func PhaseStyle

func PhaseStyle(phase string) lipgloss.Style

PhaseStyle returns the palette entry that maps to a ManagedCluster phase. Unknown phases fall through to Dim so future server-side phases don't break rendering.

func WaitFor

func WaitFor(ctx context.Context, io *cli.IOStreams, opts WaitForOpts) error

WaitFor polls opts.Poll until done, an error, a context cancellation, or opts.Timeout. Dispatches to the Bubbletea spinner (when streams support it) or a plain-text progress renderer (CI-friendly).

Types

type Palette

type Palette struct {
	Success lipgloss.Style
	Warn    lipgloss.Style
	Error   lipgloss.Style
	Dim     lipgloss.Style
}

Palette defines the CLI-wide colour scheme. Keep it small — three semantic colours plus dim — so every phase/status style maps onto the same base.

type PollFunc

type PollFunc func(ctx context.Context) (phase string, done bool, err error)

PollFunc is the per-tick probe. It returns the current phase for display, whether the wait is done (target reached or resource gone), and any terminal error (e.g., Degraded state, or a GetCluster failure that isn't an expected 404). Transient errors (GetCluster 503) are the caller's responsibility to swallow — the retry loop inside the client already handles those.

type WaitForOpts

type WaitForOpts struct {
	// Label is the human-readable noun shown in progress text, e.g.
	// "cluster prod". Renderers append DoneVerb on success ("cluster
	// prod ready" / "cluster prod deleted").
	Label string
	// DoneVerb is the past-participle verb appended to Label on the
	// success line. Defaults to "ready" (used by create/update). Pass
	// "deleted" for a delete waiter so the line reads naturally.
	DoneVerb string
	// PhaseOverride, if non-empty, replaces the live phase column in the
	// spinner. Use it when the live phase is unhelpful to the user — e.g.
	// during an `update` that doesn't transition phase, where rendering
	// "Running" while the operator is mid-reconcile is misleading. Pass
	// "Updating" / "Upgrading" / etc. and the renderer shows it instead
	// of whatever Poll returned. Leave blank for create/delete waiters
	// where the live phase IS the story.
	PhaseOverride string
	// Poll is called once per tick.
	Poll PollFunc
	// Initial polling interval. Doubles each tick up to Max.
	Interval time.Duration
	// Max is the upper bound on the polling interval.
	Max time.Duration
	// Timeout is the hard deadline. Zero → no timeout.
	Timeout time.Duration
}

WaitForOpts controls a wait run.

func (*WaitForOpts) Defaults

func (o *WaitForOpts) Defaults()

Defaults fills zero-valued fields with the CLI's standard defaults.

Jump to

Keyboard shortcuts

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