Documentation ¶
Overview ¶
Package pbars provides cli progress bars for long running tasks.
It is quick to get going with and should be customisable to your hearts content.
Index ¶
- func ByteFormatFunc(v float64) string
- func DrawBarASCII(perc float32, width int) string
- func DrawBarUTF8(perc float32, width int) string
- func FormatDuration(d time.Duration) string
- func NoUnitFunc(v float64) string
- type BarDrawerFunction
- type NaiveRateWatcher
- func (nw *NaiveRateWatcher) EstimatedRemaining() time.Duration
- func (nw *NaiveRateWatcher) EstimatedUnitsPerSecond() float32
- func (nw *NaiveRateWatcher) HasEstimate() bool
- func (nw *NaiveRateWatcher) OverallElapsed() time.Duration
- func (nw *NaiveRateWatcher) OverallUnitsPerSecond() float32
- func (nw *NaiveRateWatcher) PercentageComplete() float32
- func (nw *NaiveRateWatcher) String() string
- func (nw *NaiveRateWatcher) Update(position, length int64)
- type ProgressPrinter
- type ProgressReceiver
- type RateWatcher
- type UnitFormatFunc
- type UpdateAveragingRateWatcher
- func (nw *UpdateAveragingRateWatcher) EstimatedRemaining() time.Duration
- func (nw *UpdateAveragingRateWatcher) EstimatedUnitsPerSecond() float32
- func (nw *UpdateAveragingRateWatcher) HasEstimate() bool
- func (nw *UpdateAveragingRateWatcher) OverallElapsed() time.Duration
- func (nw *UpdateAveragingRateWatcher) OverallUnitsPerSecond() float32
- func (nw *UpdateAveragingRateWatcher) PercentageComplete() float32
- func (nw *UpdateAveragingRateWatcher) String() string
- func (nw *UpdateAveragingRateWatcher) Update(position, length int64)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ByteFormatFunc ¶
ByteFormatFunc formats bytes into B, KB, MB, GB..
func DrawBarASCII ¶
DrawBarASCII prints a bar that looks like '[===============.....]' it should be compatible with any terminal but can only print whole characters and so has slightly less resolution than others.
func DrawBarUTF8 ¶
DrawBarUTF8 prints a bar using the utf8 block characters. Because UTF8 has fractional block characters, this bar has a high resolution and is effective with less width than the ascii counterpart.
func FormatDuration ¶
FormatDuration is the same as Duration.String() but with a tweak for the number of decimal places. This implementation allows up to 2 decimals for all fields rather than the 6 or 9 that the standard version prints.
func NoUnitFunc ¶
NoUnitFunc simply formats the value as a string, no unit conversion is performed
Types ¶
type BarDrawerFunction ¶
BarDrawerFunction is a function that takes in the progress value (0.0 -> 1.0) and a width and returns a string containing the progress bar. It does not handle any other information.
type NaiveRateWatcher ¶
type NaiveRateWatcher struct {
// contains filtered or unexported fields
}
func NewNaiveRateWatcher ¶
func NewNaiveRateWatcher() *NaiveRateWatcher
func (*NaiveRateWatcher) EstimatedRemaining ¶
func (nw *NaiveRateWatcher) EstimatedRemaining() time.Duration
func (*NaiveRateWatcher) EstimatedUnitsPerSecond ¶
func (nw *NaiveRateWatcher) EstimatedUnitsPerSecond() float32
func (*NaiveRateWatcher) HasEstimate ¶
func (nw *NaiveRateWatcher) HasEstimate() bool
func (*NaiveRateWatcher) OverallElapsed ¶
func (nw *NaiveRateWatcher) OverallElapsed() time.Duration
func (*NaiveRateWatcher) OverallUnitsPerSecond ¶
func (nw *NaiveRateWatcher) OverallUnitsPerSecond() float32
func (*NaiveRateWatcher) PercentageComplete ¶
func (nw *NaiveRateWatcher) PercentageComplete() float32
func (*NaiveRateWatcher) String ¶
func (nw *NaiveRateWatcher) String() string
func (*NaiveRateWatcher) Update ¶
func (nw *NaiveRateWatcher) Update(position, length int64)
type ProgressPrinter ¶
type ProgressPrinter struct { // Title is the string printed to the left of the progress bar. It may be blank, // and it may contain utf8 characters. It is not included in the width. Title string // Output is the output writer to print the progress bar to. This is usually os.Stdout, // but for tests and certain other cases can be overriden or be nil. Output io.Writer // Width is the width of the actual bar in the progress bar. Width int // ShowPercentage sets whether the percentage should be visible on the right hand side. ShowPercentage bool // ShowRate sets whether the rate in units per second should be visible on the right hand side. ShowRate bool // ShowTimeEstimate sets whether the estimate of the remaining time should be visible on the right hand side. ShowTimeEstimate bool // UnitFunc is the formatter applied to the rate value in order to format it to subject-specific units. UnitFunc UnitFormatFunc // RateWatcher is a model that is used to track the rate, percentage, and time estimates. You probably don't // want to change this. Ratewatcher RateWatcher // Bardrawer is the function used to turn the percentage and width into a progress bar. This can be overriden to // pick between utf8 or ascii or to implement your own bar style. Bardrawer BarDrawerFunction // NonTTY can be used to set the progress bar into a nontty mode when writing output to files. The bar will be printed // only once when Done is called, and interrupt messages will function as normal. NonTTY bool // contains filtered or unexported fields }
ProgressPrinter is the model that represents a single progress bar and is responsible for printing it to the terminal correctly. It ties together all of the formatting, rate calculations, and bar drawing.
func NewProgressPrinter ¶
func NewProgressPrinter(title string, width int, utf8 bool) *ProgressPrinter
NewProgressPrinter constructs a progress bar printer for most use cases
func (*ProgressPrinter) Clear ¶
func (pp *ProgressPrinter) Clear()
Clear just clears the line using a \r character and spaces.
func (*ProgressPrinter) Done ¶
func (pp *ProgressPrinter) Done()
Done reprints the bar using the overall rate and overall elapsed time and terminates the bar with a newline.
func (*ProgressPrinter) Interruptf ¶
func (pp *ProgressPrinter) Interruptf(format string, args ...interface{})
Interruptf interrupts the bar enough to print a message and then reprint the bar on the line below.
func (*ProgressPrinter) Reprint ¶
func (pp *ProgressPrinter) Reprint()
Reprint will reprint the progress bar in place. You probably don't want to call this but its public just in case.
func (*ProgressPrinter) Update ¶
func (pp *ProgressPrinter) Update(position, length int64)
Update updates the progress bar, possibly redrawing it if the position has changed and there is and output stream attached.
type ProgressReceiver ¶
type ProgressReceiver interface { // Update performs some work based on the current progres. Update(progress, length int64) }
ProgressReceiver is the interface implemented by many of the objects in this package. It is simply a thing that can receive progress updates.
type RateWatcher ¶
type RateWatcher interface { ProgressReceiver fmt.Stringer // PercentageComplete should return a float between 0.0 and 1.0 PercentageComplete() float32 // HasEstimate HasEstimate() bool // EstimatedUnitsPerSecond should return a value representing the number of units progressing per second EstimatedUnitsPerSecond() float32 // EstimatedRemaining should return an estimated time remaining EstimatedRemaining() time.Duration // OverallUnitsPerSecond should return the overall rate seen by the watcher. Pretty much length / elapsed. OverallUnitsPerSecond() float32 // OverallElapsed should return the time since the bar was first seen by the user OverallElapsed() time.Duration }
RateWatcher presents an object that can watch the accumulation of progress updates and report the estimated rate of completion.
type UnitFormatFunc ¶
UnitFormatFunc is a function that takes in some decimal number of units and converts it to the appropriate unit.
type UpdateAveragingRateWatcher ¶
type UpdateAveragingRateWatcher struct {
// contains filtered or unexported fields
}
func NewUpdateAveragingRateWatcher ¶
func NewUpdateAveragingRateWatcher(window int) *UpdateAveragingRateWatcher
func (*UpdateAveragingRateWatcher) EstimatedRemaining ¶
func (nw *UpdateAveragingRateWatcher) EstimatedRemaining() time.Duration
func (*UpdateAveragingRateWatcher) EstimatedUnitsPerSecond ¶
func (nw *UpdateAveragingRateWatcher) EstimatedUnitsPerSecond() float32
func (*UpdateAveragingRateWatcher) HasEstimate ¶
func (nw *UpdateAveragingRateWatcher) HasEstimate() bool
func (*UpdateAveragingRateWatcher) OverallElapsed ¶
func (nw *UpdateAveragingRateWatcher) OverallElapsed() time.Duration
func (*UpdateAveragingRateWatcher) OverallUnitsPerSecond ¶
func (nw *UpdateAveragingRateWatcher) OverallUnitsPerSecond() float32
func (*UpdateAveragingRateWatcher) PercentageComplete ¶
func (nw *UpdateAveragingRateWatcher) PercentageComplete() float32
func (*UpdateAveragingRateWatcher) String ¶
func (nw *UpdateAveragingRateWatcher) String() string
func (*UpdateAveragingRateWatcher) Update ¶
func (nw *UpdateAveragingRateWatcher) Update(position, length int64)