Documentation
¶
Overview ¶
Package progress renders progress bars and spinners over an injected writer.
It is the light, dependency-free counterpart to a full progress library: a Bar shows determinate work ("[####----] 4/10 40%") and a Spinner shows indeterminate work by cycling frames. Both write to an injected io.Writer and advance only when the caller updates them — position for the bar, an explicit tick for the spinner — so rendering is deterministic and needs no real clock or background goroutine. Styling flows through an optional github.com/kbukum/gokit/cli/theme.Palette.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Bar ¶
type Bar struct {
// contains filtered or unexported fields
}
Bar is a determinate progress bar over an injected writer.
Each render overwrites the current terminal line (a leading carriage return), so successive updates animate in place; Bar.Finish moves to a fresh line. The bar only advances when the caller moves its position, so it is fully deterministic without a clock.
func NewBar ¶
NewBar creates a bar for total units of work writing to w. A non-positive total renders as an immediately complete bar.
func (*Bar) SetPosition ¶
SetPosition sets the current position, clamped to [0, total], and renders.
type BarOption ¶
type BarOption func(*Bar)
BarOption configures a Bar.
func WithBarPalette ¶
WithBarPalette styles the filled gauge and percentage with a palette.
func WithBarPrefix ¶
WithBarPrefix sets a label rendered before the gauge.
func WithBarWidth ¶
WithBarWidth sets the character width of the gauge (values below 1 are ignored).
type Spinner ¶
type Spinner struct {
// contains filtered or unexported fields
}
Spinner is an indeterminate progress indicator over an injected writer.
It advances one frame per Spinner.Tick, so animation is driven by the caller rather than a background timer — deterministic and clock-free. Each tick overwrites the current line (leading carriage return); Spinner.Finish replaces the spinner with a final glyph and message on a fresh line.
func NewSpinner ¶
func NewSpinner(w io.Writer, opts ...SpinnerOption) *Spinner
NewSpinner creates a spinner writing to w.
func (*Spinner) Finish ¶
Finish clears the spinner and writes a success glyph plus final message on a fresh line.
func (*Spinner) SetMessage ¶
SetMessage updates the message shown beside the spinner.
type SpinnerOption ¶
type SpinnerOption func(*Spinner)
SpinnerOption configures a Spinner.
func WithSpinnerGlyphs ¶
func WithSpinnerGlyphs(glyphs theme.Glyphs) SpinnerOption
WithSpinnerGlyphs selects Unicode braille frames when the glyph set supports Unicode, else the ASCII fallback, and sets the completion glyph.
func WithSpinnerMessage ¶
func WithSpinnerMessage(message string) SpinnerOption
WithSpinnerMessage sets the message rendered beside the spinner frame.
func WithSpinnerPalette ¶
func WithSpinnerPalette(palette theme.Palette) SpinnerOption
WithSpinnerPalette styles the spinner frame with a palette.