~liliace/pogs

A thread-safe Go library for displaying multiple progress bars
doc: update examples
doc: capitalize Go
doc: add and improve specificity of doc comments

clone

read-only
https://git.sr.ht/~liliace/pogs
read/write
git@git.sr.ht:~liliace/pogs

You can also use your local clone with git send-email.

#pogs Go Documentation

A thread-safe Go library for displaying multiple progress bars in unix terminals.

Progress bars typically clear and redraw the line as they update. Using a progress bar library not designed to display multiple progress bars to do so would cause each progress bar to rewrite each other.

The pogs library supports displaying multiple progress bars by moving and keeping track of the cursor position.

Additionally, the pogs library separates the method for creating a progress bar into NewBar and Start to support use cases where the jobs of the progress bar may complete before we know the number of the jobs (see example below).

#Installation

The pogs library depends on golang.org/x/sys, which hangs forever if you have GOPROXY=direct in your environment. Install with the cache proxy instead:

GOPROXY="" go get -u git.sr.ht/~liliace/pogs

#Example

In this example, we don't know the size of each progress bar until after we have finished each inner loop. We are still able to advance the progress bar data with bars.Add before displaying it with bars.Start.

bars, err := pogs.NewBars()
if err != nil {
	log.Fatal(err)
}

for _ = range 5 {
	id, _ := bars.NewBar()
	size := 0
	// consider root a pre-defined node of some linked-list
	for curr := root; curr != nil; curr = curr.Next {
		go func() {
			time.Sleep(40 * time.Millisecond)
			bars.Add(id)
		}()
		size += 1
	}
	bars.Start(id, size)
}
bars.Done()

The id returned by bars.NewBar is the id-th bar created, so the loop above can be simplified to:

for i = range 5 {
	bars.NewBar()
	size := 0
	for curr := root; curr != nil; curr = curr.Next {
		go func() {
			time.Sleep(40 * time.Millisecond)
			bars.Add(id)
		}()
		size += 1
	}
	bars.Start(i, size)
}