progress

package
v0.0.0-...-ac81b06 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2015 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package progress exposes utilities to asynchronously monitor and display processing progress.

Index

Constants

View Source
const (
	DefaultWaitTime = 3 * time.Second
	BarFilling      = "#"
	BarEmpty        = "."
	BarLeft         = "["
	BarRight        = "]"
)
View Source
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.

func (*Bar) Stop

func (pb *Bar) Stop()

Stop kills the Bar goroutine, stopping it from writing. Generally called as

myBar.Start()
defer myBar.Stop()

to stop leakage

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

func NewProgressBarManager(w io.Writer, waitTime time.Duration) *Manager

NewProgressBarManager returns an initialized Manager with the given time.Duration to wait between writes

func (*Manager) Attach

func (manager *Manager) Attach(pb *Bar)

Attach registers the given progress bar with the manager. Should be used as

myManager.Attach(myBar)
defer myManager.Detach(myBar)

func (*Manager) Detach

func (manager *Manager) Detach(pb *Bar)

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

func (*Manager) Start

func (manager *Manager) Start()

Start kicks of the timed batch writing of progress bars.

func (*Manager) Stop

func (manager *Manager) Stop()

Stop ends the main manager goroutine, stopping the manager's bars from being rendered.

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.

Jump to

Keyboard shortcuts

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