progress

package module
v0.0.0-...-5aad845 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package progress provides a way to display progress bars in the terminal.

Index

Constants

This section is empty.

Variables

View Source
var (
	Head      byte = '>'
	Filler    byte = '='
	Empty     byte = '-'
	Delimiter byte = '|'
)
View Source
var (
	ErrTotalReached = errors.New("total reached")
	ErrNotDone      = errors.New("not done")
	ErrInvalidWidth = errors.New("invalid width")
	ErrInvalidValue = errors.New("invalid value")
)
View Source
var (
	Stdout      io.Writer     = os.Stdout
	Stderr      io.Writer     = os.Stderr
	RefreshRate time.Duration = 10 * time.Millisecond
)

Functions

func Listen

func Listen()

Listen listens for updates and renders the progress bars

func Start

func Start()

Start starts the rendering the progress of progress bars using the DefaultProgress. It listens for updates using `bar.Set(n)` and new bars when added using `AddBar`

func Stop

func Stop()

Stop stops listening

Types

type Bar

type Bar struct {
	TimeStarted time.Time

	MarginLeft int

	Width int

	MarginRight int

	Bar       byte
	Empty     byte
	Delimiter byte
	Head      byte
	// contains filtered or unexported fields
}

func Add

func Add(total int) *Bar

Add adds a new bar to the default progress bar

func NewBar

func NewBar(total int) *Bar

func (*Bar) Bytes

func (b *Bar) Bytes() []byte

Bytes returns the byte presentation of the progress bar

func (*Bar) CompletedPercent

func (b *Bar) CompletedPercent() float64

CompletedPercent return the percent completed

func (*Bar) CompletedPercentString

func (b *Bar) CompletedPercentString() string

CompletedPercentString returns the formatted string representation of the completed percent

func (*Bar) Current

func (b *Bar) Current() int

Current returns the current progress of the bar

func (*Bar) Done

func (p *Bar) Done() error

func (*Bar) Incr

func (b *Bar) Incr() bool

func (*Bar) Increment

func (p *Bar) Increment() error

func (*Bar) Set

func (b *Bar) Set(current int) error

func (*Bar) String

func (b *Bar) String() string

func (*Bar) TimeElapsed

func (b *Bar) TimeElapsed() time.Duration

TimeElapsed returns the time elapsed

type Progress

type Progress struct {
	Out io.Writer

	Bars        []*Bar
	Width       int
	RefreshRate time.Duration
	// contains filtered or unexported fields
}

func New

func New() *Progress

func (*Progress) Add

func (p *Progress) Add(total int) *Bar

Add adds a new bar to the progress bar

func (*Progress) Bypass

func (p *Progress) Bypass() io.Writer

Bypass returns a writer which allows non-buffered data to be written to the underlying output

func (*Progress) Listen

func (p *Progress) Listen()

Listen listens for updates and renders the progress bars

func (*Progress) SetOut

func (p *Progress) SetOut(o io.Writer)

SetOut sets the output writer for the progress bar

func (*Progress) SetRefreshRate

func (p *Progress) SetRefreshRate(interval time.Duration)

SetRefreshRate sets the refresh rate for the progress bar

func (*Progress) Start

func (p *Progress) Start()

Start starts the rendering the progress of progress bars. It listens for updates using `bar.Set(n)` and new bars when added using `AddBar`

func (*Progress) Stop

func (p *Progress) Stop()

Stop stops listening

Jump to

Keyboard shortcuts

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