ui

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package ui owns every human-facing write: what gets said, to which stream, and whether anyone is there to read it.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConfirmTitle

func ConfirmTitle(action, subject string) string

Separated from Confirm so the wording stays testable: huh drives a real terminal session, which `go test` cannot exercise.

Types

type Option

type Option struct {
	Label string
	Value string
}

type Options

type Options struct {
	Out, Err  io.Writer
	Quiet     bool
	NoInput   bool
	Color     bool
	StderrTTY bool
	StdinTTY  bool
	Term      string
}

Gating inputs are passed in rather than probed so tests can exercise every combination without a real terminal. Production callers use FromEnv.

type Spinner

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

A Spinner returned when the UI is not animating is inert: every method is a no-op, so callers never branch on whether one is live.

func (*Spinner) Stop

func (s *Spinner) Stop()

Safe to call more than once. Failing to restore the cursor leaves the user's shell with an invisible one after we exit.

func (*Spinner) String

func (s *Spinner) String() string

For debugging; never rendered to the user.

func (*Spinner) Update

func (s *Spinner) Update(msg string)

Callers tick this on completed work rather than on a timer, so a stall shows as a frozen count rather than an animation implying progress.

type UI

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

func FromEnv

func FromEnv(quiet, noInput, color bool) *UI

NO_COLOR is applied here rather than in New so Options stays a pure description of state, testable without touching the environment.

func New

func New(o Options) *UI

func (*UI) Confirm

func (u *UI) Confirm(action, subject string) error

Refuses rather than prompting when input is unavailable, so scripts fail loudly instead of hanging or proceeding blind.

func (*UI) Data

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

Data is the command's result. stdout, never silenced: --quiet suppresses progress, not the thing that was asked for.

func (*UI) EmptyState

func (u *UI) EmptyState(resource string)

func (*UI) Failure

func (u *UI) Failure(err error)

Not gated on --quiet: a silent non-zero exit is worse than an unwanted line.

func (*UI) Info

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

Info is commentary: progress, context, next steps. stderr, silenced by --quiet.

func (*UI) NoInput

func (u *UI) NoInput() bool

func (*UI) Quiet

func (u *UI) Quiet() bool

func (*UI) Receipt

func (u *UI) Receipt(verb, resource, id string)

Silent when id is empty: a vague "Created something" is worse than nothing. stderr only, so piping the object itself to jq is unaffected.

func (*UI) Select

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

Prefer SelectWithHint wherever a flag exists: this refusal message is vaguer.

func (*UI) SelectWithHint

func (u *UI) SelectWithHint(title, flagHint string, opts []Option) (string, error)

flagHint names the flag a scripted caller should pass instead, so the refusal under --no-input is actionable.

func (*UI) Spinner

func (u *UI) Spinner(msg string) *Spinner

Returns an inert handle when animation is suppressed (not a TTY, TERM=dumb, or --quiet). Always pair with Stop.

func (*UI) StatusLine

func (u *UI) StatusLine(s string)

StatusLine is the dim context footer under table output.

func (*UI) Success

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

Jump to

Keyboard shortcuts

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