progress

package
v12.41.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2022 License: Apache-2.0 Imports: 11 Imported by: 1

Documentation

Overview

Package progress provides methods and structs for creating terminal progress bar

Index

Examples

Constants

View Source
const MIN_WIDTH = 80

MIN_WIDTH is minimal progress bar width

View Source
const PROGRESS_BAR_SYMBOL = "—"

PROGRESS_BAR_SYMBOL is symbol for creating progress bar

Variables

View Source
var DefaultSettings = Settings{
	RefreshRate:       100 * time.Millisecond,
	NameColorTag:      "{b}",
	BarFgColorTag:     "{r}",
	BarBgColorTag:     "{s-}",
	PercentColorTag:   "{m}",
	SpeedColorTag:     "{r}",
	ProgressColorTag:  "{g}",
	RemainingColorTag: "{c}",
	ShowName:          true,
	ShowPercentage:    true,
	ShowProgress:      true,
	ShowSpeed:         true,
	ShowRemaining:     true,
	IsSize:            true,
	Width:             88,
}

DefaultSettings is default progress bar settings

Functions

This section is empty.

Types

type Bar

type Bar struct {
	// contains filtered or unexported fields
}

Bar is progress bar struct

func New

func New(total int64, name string) *Bar

New creates new progress bar struct

Example
pb := New(1000, "Downloading...")

pbs := DefaultSettings
pbs.RefreshRate = 50 * time.Millisecond
pbs.ShowSpeed = false
pbs.ShowRemaining = false

defer pb.Finish()

pb.Start()

for range time.NewTicker(time.Second).C {
	pb.Add(1)
}
Output:

func (*Bar) Add

func (b *Bar) Add(v int)

func (*Bar) Add64

func (b *Bar) Add64(v int64)

Add64 adds given value ti

func (*Bar) Current

func (b *Bar) Current() int64

Current returns current progress bar value

func (*Bar) Finish

func (b *Bar) Finish()

Finish finishes progress processing

func (*Bar) IsFinished

func (b *Bar) IsFinished() bool

IsFinished returns true if progress proccesing is finished

func (*Bar) IsStarted

func (b *Bar) IsStarted() bool

IsStarted returns true if progress proccesing is started

func (*Bar) Name

func (b *Bar) Name() string

Name returns progress bar name

func (*Bar) Reader

func (b *Bar) Reader(r io.Reader) io.Reader

Reader creates and returns pass thru proxy reader

func (*Bar) SetCurrent

func (b *Bar) SetCurrent(v int64)

SetCurrent sets current progress bar value

func (*Bar) SetName

func (b *Bar) SetName(name string)

SetName sets progress bar name

func (*Bar) SetTotal

func (b *Bar) SetTotal(v int64)

SetTotal sets total progress bar value

func (*Bar) Start

func (b *Bar) Start()

Start starts progress processing

func (*Bar) Total

func (b *Bar) Total() int64

Total returns total progress bar value

func (*Bar) UpdateSettings

func (b *Bar) UpdateSettings(s Settings)

UpdateSettings updates progress settings

func (*Bar) Writer

func (b *Bar) Writer(w io.Writer) io.Writer

Writer creates and returns pass thru proxy reader

type PassThruCalc

type PassThruCalc struct {
	// contains filtered or unexported fields
}

PassThruCalc is pass thru calculator struct

func NewPassThruCalc

func NewPassThruCalc(total int64, winSizeSec float64) *PassThruCalc

NewPassThruCalc creates new pass thru calculator

func (*PassThruCalc) Calculate

func (p *PassThruCalc) Calculate(v int64) (float64, time.Duration)

Calculate calculates number of objects per seconds and remaining time

func (*PassThruCalc) SetTotal

func (p *PassThruCalc) SetTotal(v int64)

SetTotal sets total number of objects

type Settings

type Settings struct {
	RefreshRate time.Duration

	NameColorTag      string
	BarFgColorTag     string
	BarBgColorTag     string
	PercentColorTag   string
	ProgressColorTag  string
	SpeedColorTag     string
	RemainingColorTag string

	ShowSpeed      bool
	ShowName       bool
	ShowPercentage bool
	ShowProgress   bool
	ShowRemaining  bool

	Width    int
	NameSize int

	IsSize bool
}

Settings contains progress bar settings

Jump to

Keyboard shortcuts

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