Documentation ¶
Overview ¶
Package progress exposes utilities to asynchronously monitor and display processing progress.
Index ¶
Constants ¶
const ( DefaultWaitTime = 3 * time.Second BarFilling = "#" BarEmpty = "." BarLeft = "[" BarRight = "]" )
const GridPadding = 2
Variables ¶
This section is empty.
Functions ¶
func NewCounter ¶
func NewCounter(max int64) *countProgressor
Types ¶
type Bar ¶
type Bar struct { // Name is an identifier printed along with the bar Name string // BarLength is the number of characters used to print the bar BarLength int // IsBytes denotes whether byte-specific formatting (kB, MB, GB) should // be applied to the numeric output IsBytes bool // Watching is the object that implements the Progressor to expose the // values necessary for calculation Watching Progressor // Writer is where the Bar is written out to Writer io.Writer // WaitTime is the time to wait between writing the bar WaitTime time.Duration // contains filtered or unexported fields }
Bar is a tool for concurrently monitoring the progress of a task with a simple linear ASCII visualization
func (*Bar) Start ¶
func (pb *Bar) Start()
Start starts the Bar goroutine. Once Start is called, a bar will be written to the given Writer at regular intervals. The goroutine can only be stopped manually using the Stop() method. The Bar must be set up before calling this. Panics if Start has already been called.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager handles thread-safe synchronized progress bar writing, so that all given progress bars are written in a group at a given interval. The current implementation maintains insert order when printing, such that new bars appear at the bottom of the group.
func NewProgressBarManager ¶
NewProgressBarManager returns an initialized Manager with the given time.Duration to wait between writes
func (*Manager) Attach ¶
Attach registers the given progress bar with the manager. Should be used as
myManager.Attach(myBar) defer myManager.Detach(myBar)
func (*Manager) Detach ¶
Detach removes the given progress bar from the manager. Insert order is maintained for consistent ordering of the printed bars.
Note: the manager removes progress bars by "Name" not by memory location
type Progressor ¶
type Progressor interface { // Progress returns a pair of integers: the total amount to reach 100%, and // the amount completed. This method is called by progress.Bar to // determine what percentage to display. Progress() (int64, int64) }
Progressor can be implemented to allow an object to hook up to a progress.Bar.
type Updateable ¶
type Updateable interface { // Inc increments the current progress counter by the given amount. Inc(amount int64) // Set resets the progress counter to the given amount. Set(amount int64) }
Updateable is an interface which exposes the ability for a progressing value to be incremented, or reset.