decor

package
Version: v3.4.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2019 License: BSD-3-Clause Imports: 10 Imported by: 286

Documentation

Overview

 Package decor contains common decorators used by "github.com/vbauerster/mpb" package.

 Some decorators returned by this package might have a closure state. It is ok to use
 decorators concurrently, unless you share the same decorator among multiple
 *mpb.Bar instances. To avoid data races, create new decorator per *mpb.Bar instance.

 Don't:

	 p := mpb.New()
	 name := decor.Name("bar")
	 p.AddBar(100, mpb.AppendDecorators(name))
	 p.AddBar(100, mpb.AppendDecorators(name))

 Do:

	p := mpb.New()
	p.AddBar(100, mpb.AppendDecorators(decor.Name("bar1")))
	p.AddBar(100, mpb.AppendDecorators(decor.Name("bar2")))

Index

Constants

View Source
const (
	KiB = 1 << (iota * 10)
	MiB
	GiB
	TiB
)
View Source
const (
	KB = 1000
	MB = KB * 1000
	GB = MB * 1000
	TB = GB * 1000
)
View Source
const (
	UnitKiB
	UnitKB
)
View Source
const (
	// DidentRight bit specifies identation direction.
	// |foo   |b     | With DidentRight
	// |   foo|     b| Without DidentRight
	DidentRight = 1 << iota

	// DextraSpace bit adds extra space, makes sense with DSyncWidth only.
	// When DidentRight bit set, the space will be added to the right,
	// otherwise to the left.
	DextraSpace

	// DSyncWidth bit enables same column width synchronization.
	// Effective with multiple bars only.
	DSyncWidth

	// DSyncWidthR is shortcut for DSyncWidth|DidentRight
	DSyncWidthR = DSyncWidth | DidentRight

	// DSyncSpace is shortcut for DSyncWidth|DextraSpace
	DSyncSpace = DSyncWidth | DextraSpace

	// DSyncSpaceR is shortcut for DSyncWidth|DextraSpace|DidentRight
	DSyncSpaceR = DSyncWidth | DextraSpace | DidentRight
)

Variables

View Source
var (
	WCSyncWidth  = WC{C: DSyncWidth}
	WCSyncWidthR = WC{C: DSyncWidthR}
	WCSyncSpace  = WC{C: DSyncSpace}
	WCSyncSpaceR = WC{C: DSyncSpaceR}
)

Global convenience shortcuts

Functions

This section is empty.

Types

type AmountReceiver

type AmountReceiver interface {
	NextAmount(int, ...time.Duration)
}

AmountReceiver interface. If decorator needs to receive increment amount, so this is the right interface to implement.

type CounterKB

type CounterKB int64

func (CounterKB) Format

func (c CounterKB) Format(st fmt.State, verb rune)

type CounterKiB

type CounterKiB int64

func (CounterKiB) Format

func (c CounterKiB) Format(st fmt.State, verb rune)

type Decorator

type Decorator interface {
	Decor(*Statistics) string
	Syncable
}

Decorator interface. A decorator must implement this interface, in order to be used with mpb library.

func AverageETA

func AverageETA(style TimeStyle, wcc ...WC) Decorator

AverageETA decorator.

`style` one of [ET_STYLE_GO|ET_STYLE_HHMMSS|ET_STYLE_HHMM|ET_STYLE_MMSS]

`wcc` optional WC config

func AverageSpeed

func AverageSpeed(unit int, unitFormat string, wcc ...WC) Decorator

AverageSpeed decorator with dynamic unit measure adjustment.

`unit` one of [0|UnitKiB|UnitKB] zero for no unit

`unitFormat` printf compatible verb for value, like "%f" or "%d"

`wcc` optional WC config

unitFormat example if UnitKiB is chosen:

"%.1f" = "1.0MiB/s" or "% .1f" = "1.0 MiB/s"

func Counters

func Counters(unit int, pairFormat string, wcc ...WC) Decorator

Counters decorator with dynamic unit measure adjustment.

`unit` one of [0|UnitKiB|UnitKB] zero for no unit

`pairFormat` printf compatible verbs for current and total, like "%f" or "%d"

`wcc` optional WC config

pairFormat example if UnitKB is chosen:

"%.1f / %.1f" = "1.0MB / 12.0MB" or "% .1f / % .1f" = "1.0 MB / 12.0 MB"

func CountersKibiByte

func CountersKibiByte(pairFormat string, wcc ...WC) Decorator

CountersKibiByte is a wrapper around Counters with predefined unit UnitKiB (bytes/1024).

func CountersKiloByte

func CountersKiloByte(pairFormat string, wcc ...WC) Decorator

CountersKiloByte is a wrapper around Counters with predefined unit UnitKB (bytes/1000).

func CountersNoUnit

func CountersNoUnit(pairFormat string, wcc ...WC) Decorator

CountersNoUnit is a wrapper around Counters with no unit param.

func Elapsed

func Elapsed(style TimeStyle, wcc ...WC) Decorator

Elapsed returns elapsed time decorator.

`style` one of [ET_STYLE_GO|ET_STYLE_HHMMSS|ET_STYLE_HHMM|ET_STYLE_MMSS]

`wcc` optional WC config

func EwmaETA

func EwmaETA(style TimeStyle, age float64, wcc ...WC) Decorator

EwmaETA exponential-weighted-moving-average based ETA decorator.

`style` one of [ET_STYLE_GO|ET_STYLE_HHMMSS|ET_STYLE_HHMM|ET_STYLE_MMSS]

`age` is the previous N samples to average over.

`wcc` optional WC config

func EwmaSpeed

func EwmaSpeed(unit int, unitFormat string, age float64, wcc ...WC) Decorator

EwmaSpeed exponential-weighted-moving-average based speed decorator, with dynamic unit measure adjustment.

`unit` one of [0|UnitKiB|UnitKB] zero for no unit

`unitFormat` printf compatible verb for value, like "%f" or "%d"

`average` MovingAverage implementation

`wcc` optional WC config

unitFormat example if UnitKiB is chosen:

"%.1f" = "1.0MiB/s" or "% .1f" = "1.0 MiB/s"

func MovingAverageETA

func MovingAverageETA(style TimeStyle, average MovingAverage, normalizer TimeNormalizer, wcc ...WC) Decorator

MovingAverageETA decorator relies on MovingAverage implementation to calculate its average.

`style` one of [ET_STYLE_GO|ET_STYLE_HHMMSS|ET_STYLE_HHMM|ET_STYLE_MMSS]

`average` available implementations of MovingAverage [ewma.MovingAverage|NewMedian|NewMedianEwma]

`normalizer` available implementations are [NopNormalizer|FixedIntervalTimeNormalizer|MaxTolerateTimeNormalizer]

`wcc` optional WC config

func MovingAverageSpeed

func MovingAverageSpeed(unit int, unitFormat string, average MovingAverage, wcc ...WC) Decorator

MovingAverageSpeed decorator relies on MovingAverage implementation to calculate its average.

`unit` one of [0|UnitKiB|UnitKB] zero for no unit

`unitFormat` printf compatible verb for value, like "%f" or "%d"

`average` MovingAverage implementation

`wcc` optional WC config

func Name

func Name(name string, wcc ...WC) Decorator

Name returns name decorator.

`name` string to display

`wcc` optional WC config

func OnComplete

func OnComplete(decorator Decorator, message string) Decorator

OnComplete returns decorator, which wraps provided decorator, with sole purpose to display provided message on complete event.

`decorator` Decorator to wrap

`message` message to display on complete event

func Percentage

func Percentage(wcc ...WC) Decorator

Percentage returns percentage decorator.

`wcc` optional WC config

func StaticName

func StaticName(name string, wcc ...WC) Decorator

StaticName returns name decorator.

`name` string to display

`wcc` optional WC config

type MovingAverage

type MovingAverage interface {
	Add(float64)
	Value() float64
	Set(float64)
}

MovingAverage is the interface that computes a moving average over a time-series stream of numbers. The average may be over a window or exponentially decaying.

func NewMedian

func NewMedian() MovingAverage

NewMedian is fixed last 3 samples median MovingAverage.

func NewMedianEwma

func NewMedianEwma(age ...float64) MovingAverage

NewMedianEwma is ewma based MovingAverage, which gets its values from median MovingAverage.

type OnCompleteMessenger

type OnCompleteMessenger interface {
	OnCompleteMessage(string)
}

OnCompleteMessenger interface. Decorators implementing this interface suppose to return provided string on complete event.

type ShutdownListener

type ShutdownListener interface {
	Shutdown()
}

ShutdownListener interface. If decorator needs to be notified once upon bar shutdown event, so this is the right interface to implement.

type SpeedKB

type SpeedKB float64

func (SpeedKB) Format

func (s SpeedKB) Format(st fmt.State, verb rune)

type SpeedKiB

type SpeedKiB float64

func (SpeedKiB) Format

func (s SpeedKiB) Format(st fmt.State, verb rune)

type Statistics

type Statistics struct {
	ID        int
	Completed bool
	Total     int64
	Current   int64
}

Statistics is a struct, which gets passed to a Decorator.

type Syncable

type Syncable interface {
	Syncable() (bool, chan int)
}

Syncable interface. All decorators implement this interface implicitly. Its Syncable method exposes width sync channel, if sync is enabled.

type TimeNormalizer

type TimeNormalizer func(time.Duration) time.Duration

func FixedIntervalTimeNormalizer

func FixedIntervalTimeNormalizer(updInterval int) TimeNormalizer

func MaxTolerateTimeNormalizer

func MaxTolerateTimeNormalizer(maxTolerate time.Duration) TimeNormalizer

func NopNormalizer

func NopNormalizer() TimeNormalizer

type TimeStyle

type TimeStyle int

TimeStyle enum.

const (
	ET_STYLE_GO TimeStyle = iota
	ET_STYLE_HHMMSS
	ET_STYLE_HHMM
	ET_STYLE_MMSS
)

TimeStyle kinds.

type WC

type WC struct {
	W int
	C int
	// contains filtered or unexported fields
}

WC is a struct with two public fields W and C, both of int type. W represents width and C represents bit set of width related config. A decorator should embed WC, in order to become Syncable.

func (WC) FormatMsg

func (wc WC) FormatMsg(msg string) string

FormatMsg formats final message according to WC.W and WC.C. Should be called by any Decorator implementation.

func (*WC) Init

func (wc *WC) Init()

Init initializes width related config.

func (*WC) Syncable

func (wc *WC) Syncable() (bool, chan int)

Syncable is implementation of Syncable interface.

Jump to

Keyboard shortcuts

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