Documentation
¶
Index ¶
- Variables
- func Listen()
- func PadLeft(str string, length int, pad byte) string
- func PadRight(str string, length int, pad byte) string
- func PrettyTime(t time.Duration) string
- func Resize(s string, length uint) string
- func Start()
- func Stop()
- type Bar
- func (b *Bar) AppendCompleted() *Bar
- func (b *Bar) AppendElapsed() *Bar
- func (b *Bar) AppendFunc(f DecoratorFunc) *Bar
- func (b *Bar) Bytes() []byte
- func (b *Bar) CompletedPercent() float64
- func (b *Bar) CompletedPercentString() string
- func (b *Bar) Current() int
- func (b *Bar) Incr(o int) bool
- func (b *Bar) IsValid() bool
- func (b *Bar) PrependCompleted() *Bar
- func (b *Bar) PrependElapsed() *Bar
- func (b *Bar) PrependFunc(f DecoratorFunc) *Bar
- func (b *Bar) Set(n int) error
- func (b *Bar) SetText(text string)
- func (b *Bar) Stop()
- func (b *Bar) String() string
- func (b *Bar) TimeElapsed() time.Duration
- func (b *Bar) TimeElapsedString() string
- type DecoratorFunc
- type Progress
- func (p *Progress) AddBar(bar *Bar) *Bar
- func (p *Progress) AddNewBar(total int) *Bar
- func (p *Progress) Bypass() io.Writer
- func (p *Progress) Listen()
- func (p *Progress) Print()
- 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 PadLeft ¶ added in v1.0.3
PadLeft returns a new string of a specified length in which the beginning of the current string is padded with spaces or with a specified Unicode character.
func PadRight ¶ added in v1.0.3
PadRight returns a new string of a specified length in which the end of the current string is padded with spaces or with a specified Unicode character.
func PrettyTime ¶ added in v1.0.3
PrettyTime returns the string representation of the duration. It rounds the time duration to a second and returns a "---" when duration is 0
func Resize ¶ added in v1.0.3
Resize resizes the string with the given length. It ellipses with '...' when the string's length exceeds the desired length or pads spaces to the right of the string when length is smaller than desired
Types ¶
type Bar ¶
type Bar struct {
// Total of the total for the progress bar
Total int
// 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
// Data represents additional data which can be
// used in DecoratorFuncs
Data interface{}
// Donetext Text of the bar if done
Donetext string
// contains filtered or unexported fields
}
Bar represents a progress bar
func AddNewBar ¶ added in v1.0.2
AddNewBar creates a new progress bar and adds it to the default progress container
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) CompletedPercent ¶
CompletedPercent return the percent completed
func (*Bar) CompletedPercentString ¶
CompletedPercentString returns the formatted string representation of the completed percent
func (*Bar) Incr ¶
Incr increments the current value by o, time elapsed to current time and returns true. It returns false if the cursor has reached or exceeds total value.
func (*Bar) IsValid ¶ added in v1.0.5
IsValid return true if bar is not nil and assigned to a progress
func (*Bar) PrependCompleted ¶
PrependCompleted prepends the precent completed 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) 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) SetText ¶ added in v1.0.4
SetText sets text of bar. Only possible after bar is not more updated
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) AddNewBar ¶ added in v1.0.2
AddNewBar creates a new progress bar and adds to the container
func (*Progress) Bypass ¶
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) SetRefreshInterval ¶
SetRefreshInterval sets refresh interval


