Documentation
¶
Overview ¶
Package progress provides status updates to the terminal as units of work are incrementally completed.
Index ¶
Constants ¶
const ( // Standard is the default tracker, and is suitable for tracking mostly unique status updates. Standard strategy = iota // Unique is suitable for tracking repetitive status updates. Unique // Fraction renders status updates to the UI as a proper fraction (x/y). Fraction // Percent renders only the percentage of completed work. Percent )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Option ¶ added in v1.0.2
type Option func(*Progress) // exported to allow callers to create []*progress.Option to pass to New(...)
Option defines a functional configuration for Progress.
func WithTheme ¶ added in v1.0.8
WithTheme allows callers to override the default color (green) of the progress bar, e.g.:
progress.New(ctx, 100, os.Stderr, progress.WithTheme("yellow"))
Silently falls back to the default ("green") if an invalid theme name is specified.
func WithTracker ¶ added in v1.0.2
func WithTracker(s strategy) Option
WithTracker allows callers to override the default progress.Standard status tracker, e.g.:
progress.New(ctx, 100, os.Stderr, progress.WithTracker(progress.Fraction))
type Progress ¶
type Progress struct {
// contains filtered or unexported fields
}
Progress implements a throttled, concurrency-safe, high-precision status indicator for workloads.
func New ¶
New initializes a throttled, concurrency-safe, high-precision work progress tracker and starts a work completion status rendering loop in the background.
The value of the `totalUnits` parameter determines the accumulation mode used internally:
pass totalUnits > 0 for weight-based accumulation (when totalUnits is known) pass totalUnits == 0 for fractional path allocation (when totalUnits is unknown)
func (*Progress) AddTotal ¶
AddTotal dynamically increases the total work budget as new tasks are discovered. It is concurrency-safe and ensures the total budget never exceeds scale.
func (*Progress) Close ¶
func (p *Progress) Close()
Close stops the background renderer and waits for cleanup to complete.
func (*Progress) InitialBudget ¶
InitialBudget returns the full internal scale (100%) to be used as the starting budget for tracking fractional progress.
func (*Progress) Report ¶
Report updates the current progress status.
if total > 0: weight represents the relative weight of the work completed, and the
progress percentage is calculated as accumulated weight / totalUnits
if total == 0: weight represents the portion of the InitialBudget(),
which must be divided among all sub-tasks by the caller