progressbar

package module
v3.14.1006 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2024 License: MIT Imports: 13 Imported by: 0

README

progressbar

build Go Report Go Docs

This repo is a significantly patched permanent fork of github.com/schollz/progressbar.

Documentation

Overview

Package progressbar implements a simple thread-safe console progress bar with some basic customization options.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(p *ProgressBar)

Option is the general type for progress bar customization options.

func OptionClearOnFinish

func OptionClearOnFinish() Option

OptionClearOnFinish makes progress bar disappear when it's finished (but not when stopped).

func OptionDescription

func OptionDescription(s string) Option

OptionDescription sets progress bar's description label.

func OptionFullWidth

func OptionFullWidth() Option

OptionFullWidth makes progress bar use full width of the console.

func OptionItsString

func OptionItsString(its string) Option

OptionItsString sets what the iterations are called. The default is "it" which would display "it/s".

func OptionShowBytes

func OptionShowBytes() Option

OptionShowBytes enables display in units of bytes/sec.

func OptionShowCount

func OptionShowCount() Option

OptionShowCount enables display of current count out of total.

func OptionShowElapsed added in v3.13.103

func OptionShowElapsed() Option

OptionShowElapsed enables elapsed time display.

func OptionShowIts

func OptionShowIts() Option

OptionShowIts enables display of iterations/second.

func OptionShowRemaining added in v3.13.103

func OptionShowRemaining() Option

OptionShowRemaining enables display of estimated remaining time in addition to elapsed time.

Has no effect on spinners as their estimated remaining time is unknown.

func OptionSpinnerStyle added in v3.13.104

func OptionSpinnerStyle(style int) Option

OptionSpinnerStyle sets spinner's visual style. Default is 9.

Available styles are restricted to 9, 14 and 59.

func OptionTheme

func OptionTheme(theme Theme) Option

OptionTheme sets progress bar's composition elements.

func OptionThrottle

func OptionThrottle(interval time.Duration) Option

OptionThrottle enables minimum time intervals between refreshing the progress bar.

Default interval is zero which makes progress bar refresh on every update.

func OptionTotalRate

func OptionTotalRate() Option

OptionTotalRate enables plain total rate display instead of default recent average rate.

func OptionUseANSICodes

func OptionUseANSICodes() Option

OptionUseANSICodes enables use of more optimized terminal I/O.

Only useful in environments with support for ANSI escape sequences.

func OptionUseColorCodes added in v3.13.103

func OptionUseColorCodes() Option

OptionUseColorCodes enables support for color codes.

func OptionVisible added in v3.13.103

func OptionVisible(show bool) Option

OptionVisible sets whether the progress bar is shown in console.

On by default, but can be useful to omit progress bar display when output is redirected etc.

func OptionWidth

func OptionWidth(width int) Option

OptionWidth sets progress bar width.

func OptionWriter

func OptionWriter(w io.Writer) Option

OptionWriter sets progress bar's output writer (defaults to os.Stdout).

type ProgressBar

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

ProgressBar is a simple customizable progress bar. It is safe for concurrent use by multiple goroutines.

func Default

func Default(max int64, description ...string) *ProgressBar

Default creates a new ProgressBar with some reasonable default options.

With max == -1 it creates a spinner.

func DefaultBytes

func DefaultBytes(maxBytes int64, description ...string) *ProgressBar

DefaultBytes creates a new ProgressBar for measuring bytes throughput with some reasonable default options.

With maxBytes == -1 it creates a spinner.

func New

func New(max int, options ...Option) *ProgressBar

New constructs a new instance of ProgressBar with specified options.

With max == -1 it creates a spinner.

func New64

func New64(max int64, options ...Option) *ProgressBar

New64 constructs a new instance of ProgressBar with specified options.

With max == -1 it creates a spinner.

func (*ProgressBar) Add

func (p *ProgressBar) Add(delta int) error

Add adds specified delta to progress bar's current value.

func (*ProgressBar) Add64

func (p *ProgressBar) Add64(delta int64) error

Add64 adds specified delta to progress bar's current value.

func (*ProgressBar) AddMax

func (p *ProgressBar) AddMax(delta int) error

AddMax adds specified delta to progress bar's maximum value.

func (*ProgressBar) AddMax64

func (p *ProgressBar) AddMax64(delta int64) error

AddMax64 adds specified delta to progress bar's maximum value.

func (*ProgressBar) Clear

func (p *ProgressBar) Clear() error

Clear erases progress bar from the current line.

func (*ProgressBar) Close

func (p *ProgressBar) Close() (err error)

Close implements io.Closer, just in case.

func (*ProgressBar) Finish

func (p *ProgressBar) Finish() error

Finish fills progress bar to full and starts a new line.

func (*ProgressBar) Max

func (p *ProgressBar) Max() int

Max returns progress bar's maximum value.

func (*ProgressBar) Max64

func (p *ProgressBar) Max64() int64

Max64 returns progress bar's maximum value.

func (*ProgressBar) Read

func (p *ProgressBar) Read(b []byte) (n int, err error)

Read implements io.Reader, just in case.

func (*ProgressBar) Reset

func (p *ProgressBar) Reset()

Reset resets progress bar to initial state.

func (*ProgressBar) Set

func (p *ProgressBar) Set(value int) error

Set sets progress bar's current value.

func (*ProgressBar) Set64

func (p *ProgressBar) Set64(value int64) error

Set64 sets progress bar's current value.

func (*ProgressBar) SetDescription

func (p *ProgressBar) SetDescription(s string)

SetDescription changes progress bar's description label.

func (*ProgressBar) SetMax

func (p *ProgressBar) SetMax(max int) error

SetMax sets progress bar's maximum value at which it's considered full.

func (*ProgressBar) SetMax64

func (p *ProgressBar) SetMax64(max int64) error

SetMax64 sets progress bar's maximum value at which it's considered full.

func (*ProgressBar) State

func (p *ProgressBar) State() State

State returns progress bar's current state.

func (*ProgressBar) Stop

func (p *ProgressBar) Stop() error

Stop stops progress bar at current state.

func (*ProgressBar) String

func (p *ProgressBar) String() string

String returns progress bar's current rendering.

func (*ProgressBar) Write

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

Write implements io.Writer, just in case.

type Reader

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

Reader is an io.Reader with a progress bar.

func NewReader

func NewReader(r io.Reader, bar *ProgressBar) Reader

NewReader creates a new Reader with given io.Reader and progress bar.

func (*Reader) Close

func (r *Reader) Close() (err error)

Close closes the internal reader if it implements io.Closer and fills progress bar to full.

func (*Reader) Read

func (r *Reader) Read(p []byte) (n int, err error)

Read reads buffer p and adds the number of bytes read to the progress bar.

type State

type State struct {
	CurrentPercent float64
	CurrentBytes   float64
	SecondsSince   float64
	SecondsLeft    float64
	KBsPerSecond   float64
}

State is a summary of progress bar's current position.

type Theme

type Theme struct {
	Saucer        string
	SaucerHead    string
	SaucerPadding string
	BarStart      string
	BarEnd        string
}

Theme defines the elements of a progress bar.

Jump to

Keyboard shortcuts

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