Documentation
¶
Overview ¶
Package ui owns every human-facing write: what gets said, to which stream, and whether anyone is there to read it.
Index ¶
- func ConfirmTitle(action, subject string) string
- type Option
- type Options
- type Spinner
- type UI
- func (u *UI) Confirm(action, subject string) error
- func (u *UI) Data(format string, a ...any)
- func (u *UI) EmptyState(resource string)
- func (u *UI) Failure(err error)
- func (u *UI) Info(format string, a ...any)
- func (u *UI) NoInput() bool
- func (u *UI) Quiet() bool
- func (u *UI) Receipt(verb, resource, id string)
- func (u *UI) Select(title string, opts []Option) (string, error)
- func (u *UI) SelectWithHint(title, flagHint string, opts []Option) (string, error)
- func (u *UI) Spinner(msg string) *Spinner
- func (u *UI) StatusLine(s string)
- func (u *UI) Success(format string, a ...any)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConfirmTitle ¶
Separated from Confirm so the wording stays testable: huh drives a real terminal session, which `go test` cannot exercise.
Types ¶
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.
type UI ¶
type UI struct {
// contains filtered or unexported fields
}
func FromEnv ¶
NO_COLOR is applied here rather than in New so Options stays a pure description of state, testable without touching the environment.
func (*UI) Confirm ¶
Refuses rather than prompting when input is unavailable, so scripts fail loudly instead of hanging or proceeding blind.
func (*UI) Data ¶
Data is the command's result. stdout, never silenced: --quiet suppresses progress, not the thing that was asked for.
func (*UI) EmptyState ¶
func (*UI) Receipt ¶
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) SelectWithHint ¶
flagHint names the flag a scripted caller should pass instead, so the refusal under --no-input is actionable.
func (*UI) Spinner ¶
Returns an inert handle when animation is suppressed (not a TTY, TERM=dumb, or --quiet). Always pair with Stop.
func (*UI) StatusLine ¶
StatusLine is the dim context footer under table output.