progress

package
v0.3.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2026 License: MIT Imports: 6 Imported by: 0

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

func NewBar(w io.Writer, total int64, opts ...BarOption) *Bar

NewBar creates a bar for total units of work writing to w. A non-positive total renders as an immediately complete bar.

func (*Bar) Finish

func (b *Bar) Finish() error

Finish fills the bar and moves to a fresh line.

func (*Bar) Inc

func (b *Bar) Inc(delta int64) error

Inc advances the position by delta (clamped) and renders.

func (*Bar) Percent

func (b *Bar) Percent() int

Percent returns the completion percentage in [0, 100].

func (*Bar) SetPosition

func (b *Bar) SetPosition(pos int64) error

SetPosition sets the current position, clamped to [0, total], and renders.

type BarOption

type BarOption func(*Bar)

BarOption configures a Bar.

func WithBarPalette

func WithBarPalette(palette theme.Palette) BarOption

WithBarPalette styles the filled gauge and percentage with a palette.

func WithBarPrefix

func WithBarPrefix(prefix string) BarOption

WithBarPrefix sets a label rendered before the gauge.

func WithBarWidth

func WithBarWidth(width int) BarOption

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

func (s *Spinner) Finish(message string) error

Finish clears the spinner and writes a success glyph plus final message on a fresh line.

func (*Spinner) SetMessage

func (s *Spinner) SetMessage(message string)

SetMessage updates the message shown beside the spinner.

func (*Spinner) Tick

func (s *Spinner) Tick() error

Tick advances to the next frame and renders it in place.

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.

Jump to

Keyboard shortcuts

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