decor

package
v3.3.1+incompatible Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2018 License: BSD-3-Clause Imports: 10 Imported by: 581

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
)
View Source
const (
	ET_STYLE_GO = iota
	ET_STYLE_HHMMSS
	ET_STYLE_HHMM
	ET_STYLE_MMSS
)

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)
}

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, chan<- int, <-chan int) string
}

Decorator is an interface with one method:

Decor(st *Statistics, widthAccumulator chan<- int, widthDistributor <-chan int) string

All decorators in this package implement this interface.

func AverageETA

func AverageETA(style int, 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 int, 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 int, 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 int, average MovingAverage, 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` MovingAverage implementation

`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, wcc ...WC) 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

`wcc` optional WC config

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 DecoratorFunc

type DecoratorFunc func(*Statistics, chan<- int, <-chan int) string

DecoratorFunc is an adapter for Decorator interface

func (DecoratorFunc) Decor

func (f DecoratorFunc) Decor(s *Statistics, widthAccumulator chan<- int, widthDistributor <-chan int) string

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, ...WC)
}

OnCompleteMessenger is an interface with one method:

OnCompleteMessage(message string, wc ...WC)

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

type ShutdownListener

type ShutdownListener interface {
	Shutdown()
}

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 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.

func (*WC) BuildFormat

func (wc *WC) BuildFormat()

BuildFormat builds initial format according to WC.C

func (WC) FormatMsg

func (wc WC) FormatMsg(msg string, widthAccumulator chan<- int, widthDistributor <-chan int) string

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

Jump to

Keyboard shortcuts

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