Documentation ¶
Overview ¶
A progress bar for arbitrary units, which can also keep track of the speed of progress in terms of units/second. Safe for concurrent use.
To keep track of speeds, have each "progress maker" report how many units of progress it has done at desired intervals using Report() with a unique identifier. If such a progress maker has finished its task, have it report it with Done(). For every X amount of reports, it will sample the average speed of all the progress makers and include it as part of the formatted progress bar string.
Index ¶
Constants ¶
const ( AutoWidth = 0 UnknownTotal = 0 )
Variables ¶
var DataUnits = []Unit{ Unit{1000000000000, "TiB"}, Unit{1000000000, "GiB"}, Unit{1000000, "MiB"}, Unit{1000, "KiB"}, Unit{1, "B"}, }
Data speed units. Useful for transfer speeds.
Functions ¶
This section is empty.
Types ¶
type ProgressBar ¶
type ProgressBar struct {
// The characters used for the empty and full parts of the bar itself.
// Uses ░ and █ by default, respectively.
Empty, Full rune
// If desired, they can be set to words describing what a unit of progress
// means. For instance "File" and "Files" if the bar represents how many files
// have been processed.
Unit, Units string
// The speed units used for reporting speed. See DataUnits for an example
// of units for data transfer/processing.
SpeedUnits []Unit
// The width of the console and the padding on the left of the bar.
// The width is AutoWidth by default, which will automatically determine
// the appropriate size depending on the terminal size.
Width, Padding int
// Number of reports that should be stored to calculate the average.
// The higher it is, the less volatile it is. Default is 50.
ReportCount, OverallReportCount int
// How many calls to Report() it should take for it to sample all
// speed and calculate an overall average speed. Default is 15.
ReportsPerSample int
// contains filtered or unexported fields
}
func NewProgressBar ¶
func NewProgressBar(total int) *ProgressBar
Creates a new progress bar starting at 0 units. If total is set to UnknownTotal, no bar will be displayed, but it will still display the number of units of progress that have been made and whatnot.
func (*ProgressBar) AverageOverallSpeed ¶
func (p *ProgressBar) AverageOverallSpeed() (avg float64)
Returns the average cumulative speed and the number of UID used to calculate it.
func (*ProgressBar) AverageSpeed ¶
func (p *ProgressBar) AverageSpeed(uid int) (float64, error)
Returns the average speed of a particular UID. Returns an error if and only if the UID doesn't exist.
func (*ProgressBar) Done ¶
func (p *ProgressBar) Done(uid int)
Report that the progress of a UID is done. This is important to call to keep an accurate overall average.
func (*ProgressBar) Progress ¶
func (p *ProgressBar) Progress(n int) int
Make n amount of units in progress.
func (*ProgressBar) Report ¶
func (p *ProgressBar) Report(uid, n int)
Report how many units of progress have been made since last call for that particular UID.
func (*ProgressBar) String ¶
func (p *ProgressBar) String() string
Gets the whole formatted progress bar.