bar

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2022 License: MIT Imports: 12 Imported by: 8

Documentation

Index

Constants

This section is empty.

Variables

View Source
var RenderColored = RenderColoured

RenderColored is an alias for RenderColoured

Functions

func Download

func Download(uri string, w io.Writer) error

func RenderRainbow

func RenderRainbow(w io.Writer, current, total int)

RenderRainbow renders a rectangular progress bar that cycles through colours as it progresses across the terminal

func RenderSimple

func RenderSimple(w io.Writer, current, total int)

RenderSimple renders a simple rectangular progress bar using the default terminal colours

func StatsAmountComplete

func StatsAmountComplete(current int64, total int64, _ float64, _ History) string

func StatsAmountRate

func StatsAmountRate(_ int64, total int64, _ float64, h History) string

func StatsBytesComplete

func StatsBytesComplete(current int64, total int64, _ float64, _ History) string

func StatsBytesRate

func StatsBytesRate(_ int64, _ int64, _ float64, h History) string

func StatsPercentComplete

func StatsPercentComplete(_ int64, total int64, fraction float64, _ History) string

func StatsTimeRemaining

func StatsTimeRemaining(_ int64, total int64, _ float64, h History) string

Types

type Bar

type Bar struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Bar is a loading bar

func Default

func Default() *Bar

Default creates a loading bar with default settings

func New

func New(options ...Option) *Bar

New creates a bar with an optional list of option for customisation

func (*Bar) AddCurrent

func (b *Bar) AddCurrent(add int) *Bar

AddCurrent adds the given value to the current value of the bar

func (*Bar) AddCurrentInt64

func (b *Bar) AddCurrentInt64(current int64) *Bar

AddCurrentInt64 adds the given int64 value to the current value of the bar

func (*Bar) Finish

func (b *Bar) Finish()

Finish finishes processing on the bar, and restores the terminal state e.g. cursor visibility You don't need to call this unless:

A. You want to stop the bar before it completes
B. Your bar has an unknown (zero) total and thus cannot know when it is complete

func (*Bar) Increment

func (b *Bar) Increment()

Increment increases the current value by 1

func (*Bar) Log

func (b *Bar) Log(format string, args ...interface{}) *Bar

func (*Bar) SetCurrent

func (b *Bar) SetCurrent(current int) *Bar

SetCurrent sets the current value of the bar

func (*Bar) SetCurrentInt64

func (b *Bar) SetCurrentInt64(current int64) *Bar

SetCurrentInt64 sets the current value of the bar with an int64

func (*Bar) SetLabel

func (b *Bar) SetLabel(label string) *Bar

SetLabel sets the label displayed at the start of the bar (this can be used to update the label during rendering)

func (*Bar) SetTotal

func (b *Bar) SetTotal(total int) *Bar

SetTotal sets the total value of the bar

func (*Bar) SetTotalInt64

func (b *Bar) SetTotalInt64(total int64) *Bar

SetTotalInt64 sets the total value of the bar with an int64

func (*Bar) Write

func (b *Bar) Write(p []byte) (n int, err error)

Write implements io.Writer on Bar, so it can be used to keep track of i/o operations using an io.MultiWriter

type History

type History []Record

func (History) AverageRatePerMS

func (h History) AverageRatePerMS() float64

func (History) ETA

func (h History) ETA(total int64) string

func (*History) Push

func (h *History) Push(record Record)

type Option

type Option func(b *Bar)

Option is a customisation function that modifies a Bar

func OptionHideOnFinish

func OptionHideOnFinish(enabled bool) Option

OptionHideOnFinish hides the bar when it is finished

func OptionWithAutoComplete

func OptionWithAutoComplete(enabled bool) Option

OptionWithAutoComplete sets whether the bar should automatically complete when the total is reached

func OptionWithLabel

func OptionWithLabel(l string) Option

OptionWithLabel sets the label for the bar (displayed to the left)

func OptionWithPadding

func OptionWithPadding(padding int) Option

OptionWithPadding sets the number of spaces to the left and right of the entire bar

func OptionWithRenderFunc

func OptionWithRenderFunc(r RenderFunc) Option

OptionWithRenderFunc sets the render function for the bar

func OptionWithStatsFuncs

func OptionWithStatsFuncs(f ...StatsFunc) Option

OptionWithStatsFuncs sets the stats functions for the bar

func OptionWithStatsPadding

func OptionWithStatsPadding(padding int) Option

OptionWithStatsPadding sets the number of spaces between the graphical bar and the stats segments

func OptionWithWriter

func OptionWithWriter(w io.Writer) Option

OptionWithWriter sets the writer for the bar

func OptionWithoutStatsFuncs

func OptionWithoutStatsFuncs() Option

OptionWithoutStatsFuncs removes all stats functions from the bar

type Record

type Record struct {
	Progress int64
	At       time.Time
}

type RenderFunc

type RenderFunc func(w io.Writer, current, total int)

RenderFunc is a function that renders the graphical portion of the progress bar

func RenderColoured

func RenderColoured(r, g, b int) RenderFunc

RenderColoured renders a progress bar in the given rgb colour

func RenderCustomCharacters

func RenderCustomCharacters(complete rune, incomplete rune) RenderFunc

RenderCustomCharacters renders a simple rectangular progress bar using the supplied characters

type StatsFunc

type StatsFunc func(current int64, total int64, fraction float64, h History) string

Jump to

Keyboard shortcuts

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