Documentation
¶
Overview ¶
package jprogress is a library to render progress bars in terminal applications
Index ¶
- Variables
- func Listen()
- func RemoveBar(bar *Bar) error
- func RemoveBarOnComplete(bar *Bar) error
- func Start()
- func Stop()
- type Bar
- func (b *Bar) Add(num int) bool
- func (b *Bar) Add64(num int64) bool
- func (b *Bar) AppendCompleted() *Bar
- func (b *Bar) AppendETA() *Bar
- func (b *Bar) AppendElapsed() *Bar
- func (b *Bar) AppendFunc(f DecoratorFunc) *Bar
- func (b *Bar) AppendSlashNum() *Bar
- func (b *Bar) AppendStr(str string) *Bar
- func (b *Bar) Bytes() []byte
- func (b *Bar) CompletedPercent() float64
- func (b *Bar) CompletedPercentString() string
- func (b *Bar) Current() int
- func (b *Bar) Current64() int64
- func (b *Bar) Finish() error
- func (b *Bar) Incr() bool
- func (b *Bar) IsComplete() bool
- func (b *Bar) PrependCompleted() *Bar
- func (b *Bar) PrependDesc(description string) *Bar
- func (b *Bar) PrependElapsed() *Bar
- func (b *Bar) PrependFunc(f DecoratorFunc) *Bar
- func (b *Bar) PrependSlashNum() *Bar
- func (b *Bar) PrependStr(str string) *Bar
- func (b *Bar) Set(n int) error
- func (b *Bar) Set64(n int64) error
- func (b *Bar) String() string
- func (b *Bar) TimeElapsed() time.Duration
- func (b *Bar) TimeElapsedString() string
- type DecoratorFunc
- type Progress
- func (p *Progress) AddBar(total int) *Bar
- func (p *Progress) Bypass() io.Writer
- func (p *Progress) Default(total int, description ...string) *Bar
- func (p *Progress) Default64(total int64, description ...string) *Bar
- func (p *Progress) Listen()
- func (p *Progress) RemoveBar(bar *Bar) error
- func (p *Progress) RemoveBarOnComplete(bar *Bar) error
- func (p *Progress) SetOut(o io.Writer)
- func (p *Progress) SetRefreshInterval(interval time.Duration)
- func (p *Progress) Start()
- func (p *Progress) Stop()
Constants ¶
This section is empty.
Variables ¶
var ( // Fill is the default character representing completed progress Fill byte = '=' // Head is the default character that moves when progress is updated Head byte = '>' // Empty is the default character that represents the empty progress Empty byte = '-' // LeftEnd is the default character in the left most part of the progress indicator LeftEnd byte = '[' // RightEnd is the default character in the right most part of the progress indicator RightEnd byte = ']' // Width is the default width of the progress bar Width = 70 // ErrMaxCurrentReached is error when trying to set current value that exceeds the total value ErrMaxCurrentReached = errors.New("errors: current value is greater total value") )
var Out = os.Stdout
Out is the default writer to render progress bars to
var RefreshInterval = time.Millisecond * 10
RefreshInterval in the default time duration to wait for refreshing the output
Functions ¶
func RemoveBarOnComplete ¶ added in v0.1.1
RemoveBarOnComplete remove bar from progress when complete
Types ¶
type Bar ¶
type Bar struct {
// Total of the total for the progress bar
Total int64
// LeftEnd is character in the left most part of the progress indicator. Defaults to '['
LeftEnd byte
// RightEnd is character in the right most part of the progress indicator. Defaults to ']'
RightEnd byte
// Fill is the character representing completed progress. Defaults to '='
Fill byte
// Head is the character that moves when progress is updated. Defaults to '>'
Head byte
// Empty is the character that represents the empty progress. Default is '-'
Empty byte
// TimeStated is time progress began
TimeStarted time.Time
// Width is the width of the progress bar
Width int
// contains filtered or unexported fields
}
Bar represents a progress bar
func (*Bar) Add ¶ added in v0.1.2
Add increments the current value by num, time elapsed to current time and returns true. It returns false if the cursor has reached or exceeds total value.
func (*Bar) Add64 ¶ added in v0.1.3
Add64 increments the current value by num, time elapsed to current time and returns true. It returns false if the cursor has reached or exceeds total value.
func (*Bar) AppendCompleted ¶
AppendCompleted appends the completion percent to the progress bar
func (*Bar) AppendElapsed ¶
AppendElapsed appends the time elapsed the be progress bar
func (*Bar) AppendFunc ¶
func (b *Bar) AppendFunc(f DecoratorFunc) *Bar
AppendFunc runs the decorator function and renders the output on the right of the progress bar
func (*Bar) AppendSlashNum ¶ added in v0.1.2
AppendSlashNum append <processed num>/<total> to the progress bar
func (*Bar) CompletedPercent ¶
CompletedPercent return the percent completed
func (*Bar) CompletedPercentString ¶
CompletedPercentString returns the formatted string representation of the completed percent
func (*Bar) Finish ¶ added in v0.1.2
Finish set the current value to total, time elapsed to current time
func (*Bar) Incr ¶
Incr increments the current value by 1, time elapsed to current time and returns true. It returns false if the cursor has reached or exceeds total value.
func (*Bar) IsComplete ¶ added in v0.1.1
CompletedPercent return the percent completed
func (*Bar) PrependCompleted ¶
PrependCompleted prepends the precent completed to the progress bar
func (*Bar) PrependDesc ¶
PrependDesc prepends <processed num>/<total> to the progress bar
func (*Bar) PrependElapsed ¶
PrependElapsed prepends the time elapsed to the begining of the bar
func (*Bar) PrependFunc ¶
func (b *Bar) PrependFunc(f DecoratorFunc) *Bar
PrependFunc runs decorator function and render the output left the progress bar
func (*Bar) PrependSlashNum ¶
PrependSlashNum prepends <processed num>/<total> to the progress bar
func (*Bar) PrependStr ¶ added in v0.1.2
PrependStr prepends str to the progress bar
func (*Bar) Set ¶
Set the current count of the bar. It returns ErrMaxCurrentReached when trying n exceeds the total value. This is atomic operation and concurrency safe.
func (*Bar) Set64 ¶ added in v0.1.3
Set64 the current count of the bar. It returns ErrMaxCurrentReached when trying n exceeds the total value. This is atomic operation and concurrency safe.
func (*Bar) TimeElapsed ¶
TimeElapsed returns the time elapsed
func (*Bar) TimeElapsedString ¶
TimeElapsedString returns the formatted string represenation of the time elapsed
type DecoratorFunc ¶
DecoratorFunc is a function that can be prepended and appended to the progress bar
type Progress ¶
type Progress struct {
// Out is the writer to render progress bars to
Out io.Writer
// Width is the width of the progress bars
Width int
// Bars is the collection of progress bars
Bars []*Bar
// RefreshInterval in the time duration to wait for refreshing the output
RefreshInterval time.Duration
// contains filtered or unexported fields
}
Progress represents the container that renders progress bars
func (*Progress) Bypass ¶
Bypass returns a writer which allows non-buffered data to be written to the underlying output
func (*Progress) Default ¶ added in v0.1.2
Default creates a new progress bar and adds to the container
func (*Progress) Default64 ¶ added in v0.1.3
Default64 creates a new progress bar and adds to the container
func (*Progress) Listen ¶
func (p *Progress) Listen()
Listen listens for updates and renders the progress bars
func (*Progress) RemoveBarOnComplete ¶ added in v0.1.1
RemoveBarOnComplete remove bar from progress when complete