ui

package
v1.0.3 Latest Latest
Warning

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

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

Documentation

Overview

Package ui is notenv's hand-rolled terminal UI: ANSI styling, prompts, an arrow-key select, and a spinner. Built on x/term raw mode, which is already a dependency, so it adds zero new supply-chain surface.

Styling honors NO_COLOR and TERM=dumb and disables itself off-TTY. All human-facing output goes to stderr; stdout stays reserved for data.

Index

Constants

This section is empty.

Variables

View Source
var ErrCanceled = errors.New("canceled")

ErrCanceled is returned when the user aborts a prompt (Esc, q, Ctrl-C).

Functions

func Bold

func Bold(s string) string

func Confirm

func Confirm(label string, def bool) (bool, error)

Confirm asks a yes/no question.

func Cyan

func Cyan(s string) string

func Dim

func Dim(s string) string

func Failf

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

func Green

func Green(s string) string

func Heading added in v0.21.1

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

Heading prints a blank line then a bold section title, opening a phase.

func Infof

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

func Input

func Input(label, def string) (string, error)

Input reads one echoed line; empty input returns def.

func Interactive

func Interactive() bool

Interactive reports whether prompts are possible at all.

func Notef

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

func Plainf added in v0.21.1

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

Plainf prints one unadorned line to stderr (no glyph), for the body of a summary block where the status vocabulary would only add noise.

func Red

func Red(s string) string

func Rule added in v0.21.1

func Rule()

Rule prints a dim horizontal rule, used to delimit a summary block.

func Select

func Select(label string, options []Option) (int, error)

Select renders an arrow-key picker on the controlling terminal and returns the chosen index. Keys: up/down (or k/j), Enter to choose, Esc/q/Ctrl-C to cancel (returns ErrCanceled). Without a usable raw-mode terminal it falls back to a numbered prompt.

func Spin

func Spin(label string, fn func() error) error

Spin runs fn while animating a spinner on stderr, then reports the outcome as a success or failure status line. Off-TTY it degrades to plain lines.

func SpinSub added in v0.21.1

func SpinSub(label string, fn func() error) error

SpinSub is Spin rendered as a sub-step of a phase: dim and indented while running, and it leaves a dim Substep line on success instead of a top-level status, so a phase's individual steps stay subordinate to its Heading. A failure still surfaces at full weight.

func Substep added in v0.21.1

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

Substep reports a completed sub-step of a phase: a dim, indented check kept subordinate to its Heading and the final summary, so the eye lands on those rather than on each internal step.

func Successf

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

func Warnf

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

func Yellow

func Yellow(s string) string

Types

type Option

type Option struct {
	Label  string
	Detail string
}

Option is one selectable entry; Detail renders dimmed after the label.

Jump to

Keyboard shortcuts

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