Documentation
¶
Index ¶
- Constants
- Variables
- func HowLongAgo(sec int64) string
- type BarChars
- type Progress
- func Bar(maxSteps ...int) *Progress
- func Counter(maxSteps ...int) *Progress
- func CustomBar(width int, cs BarChars) *Progress
- func DynamicText(messages map[int]string) *Progress
- func Full(maxSteps ...int) *Progress
- func LoadBar(chars []rune) *Progress
- func LoadingBar(chars []rune) *Progress
- func New(maxSteps ...int) *Progress
- func NewWithConfig(fn func(p *Progress), maxSteps ...int) *Progress
- func RoundTrip(char rune, charNumAndBoxWidth ...int) *Progress
- func Tape(maxSteps ...int) *Progress
- func Txt(maxSteps ...int) *Progress
- func (p *Progress) AddMessage(name, message string)
- func (p *Progress) AddMessages(msgMap map[string]string)
- func (p *Progress) AddWidget(name string, handler WidgetFunc) *Progress
- func (p *Progress) AddWidgets(widgets map[string]WidgetFunc)
- func (p *Progress) Advance(steps ...uint)
- func (p *Progress) AdvanceTo(step uint)
- func (p *Progress) Binding(data interface{}) *Progress
- func (p *Progress) Bound() interface{}
- func (p *Progress) Config(fn func(p *Progress)) *Progress
- func (p *Progress) Destroy()
- func (p *Progress) Display()
- func (p *Progress) Finish(message ...string)
- func (p *Progress) FinishedAt() time.Time
- func (p *Progress) Handler(name string) WidgetFunc
- func (p *Progress) Percent() float32
- func (p *Progress) Progress() uint
- func (p *Progress) SetWidget(name string, handler WidgetFunc) *Progress
- func (p *Progress) Start(maxSteps ...int)
- func (p *Progress) StartedAt() time.Time
- func (p *Progress) Step() uint
- func (p *Progress) WithMaxSteps(maxSteps ...int) *Progress
- type ProgressBar
- type ProgressFace
- type RoundTripBar
- type WidgetFunc
Examples ¶
Constants ¶
const ( CharStar rune = '*' CharPlus rune = '+' CharWell rune = '#' CharEqual rune = '=' CharEqual1 rune = '═' CharSpace rune = ' ' CharCenter rune = '●' CharSquare rune = '■' CharSquare1 rune = '▇' CharSquare2 rune = '▉' CharSquare3 rune = '░' CharSquare4 rune = '▒' // Hyphen Minus CharHyphen rune = '-' CharCNHyphen rune = '—' CharUnderline rune = '_' CharLeftArrow rune = '<' CharRightArrow rune = '>' CharRightArrow1 rune = '▶' )
some built in chars
const ( DefBarWidth = 60 DefBarFormat = "{@bar} {@percent:4s}%({@current}/{@max}){@message}" FullBarFormat = "{@bar} {@percent:4s}%({@current}/{@max}) {@elapsed:7s}/{@estimated:-7s} {@memory:6s}" )
internal format for ProgressBar
const ( MinFormat = "{@message}{@current}" TxtFormat = "{@message}{@percent:4s}%({@current}/{@max})" DefFormat = "{@message}{@percent:4s}%({@current}/{@max})" FullFormat = "{@percent:4s}%({@current}/{@max}) {@elapsed:7s}/{@estimated:-7s} {@memory:6s}" )
internal format for Progress
Variables ¶
var ( BarCharsStyle = BarChars{'#', '>', ' '} BarCharsStyle1 = BarChars{'▉', '▉', '░'} BarCharsStyle2 = BarChars{'■', '■', ' '} BarCharsStyle3 = BarChars{'■', '▶', ' '} BarCharsStyle4 = BarChars{'=', '>', ' '} )
some built in BarChars style
var ( LoadingTheme1 = []rune{'-', '\\', '|', '/'} LoadingTheme2 = []rune{'◐', '◒', '◓', '◑'} LoadingTheme3 = []rune{'✣', '✤', '✥', '❉'} LoadingTheme4 = []rune{'卍', '卐'} LoadingTheme5 = []rune("⌞⌟⌝⌜") LoadingTheme6 = []rune("◎●◯◌○⊙") LoadingTheme7 = []rune("㊎㊍㊌㊋㊏") )
default spinner chars: -\|/
Functions ¶
Types ¶
type BarChars ¶
type BarChars struct {
Completed, Processing, Remaining rune
}
BarChars setting for a progress bar. default {'#', '>', ' '}
type Progress ¶
type Progress struct {
// Format string the bar format
Format string
// MaxSteps maximal steps.
MaxSteps uint
// StepWidth the width for display "{@current}". default is 2
StepWidth uint8
// Overwrite prev output. default is True
Overwrite bool
// RedrawFreq redraw freq. default is 1
RedrawFreq uint8
// Widgets for build the progress bar
Widgets map[string]WidgetFunc
// Messages named messages for build progress bar
// Example:
// {"msg": "downloading ..."}
// "{@percent}% {@msg}" -> "83% downloading ..."
Messages map[string]string
// contains filtered or unexported fields
}
Progress definition Refer:
https://github.com/inhere/php-console/blob/master/src/Utils/ProgressBar.php
func DynamicText ¶
DynamicText progress bar create
func NewWithConfig ¶
NewWithConfig create new Progress
func RoundTrip ¶
RoundTrip create a RoundTrip progress bar. Usage:
p := RoundTrip(CharEqual)
// p := RoundTrip('*') // custom char
p.Start()
....
p.Finish()
func (*Progress) AddMessage ¶
AddMessage to progress instance
func (*Progress) AddMessages ¶
AddMessages to progress instance
func (*Progress) AddWidget ¶
func (p *Progress) AddWidget(name string, handler WidgetFunc) *Progress
AddWidget to progress instance
func (*Progress) AddWidgets ¶
func (p *Progress) AddWidgets(widgets map[string]WidgetFunc)
AddWidgets to progress instance
func (*Progress) Destroy ¶
func (p *Progress) Destroy()
Destroy removes the progress bar from the current line.
This is useful if you wish to write some output while a progress bar is running. Call display() to show the progress bar again.
func (*Progress) Display ¶
func (p *Progress) Display()
Display outputs the current progress string.
func (*Progress) Finish ¶
Finish the progress output. if provide finish message, will delete progress bar then print the message.
func (*Progress) Handler ¶
func (p *Progress) Handler(name string) WidgetFunc
Handler get widget handler by widget name
func (*Progress) SetWidget ¶
func (p *Progress) SetWidget(name string, handler WidgetFunc) *Progress
SetWidget to progress instance
func (*Progress) WithMaxSteps ¶
WithMaxSteps setting max steps
type ProgressBar ¶
type ProgressBar struct {
// Width for the bar. default is 100
Width int
// Chars config for the bar. default {'#', '>', ' '}
Chars BarChars
}
ProgressBar definition. Preview:
1 [->--------------------------] 3 [■■■>------------------------] 25/50 [==============>-------------] 50%
func (ProgressBar) Create ¶
func (pb ProgressBar) Create(maxSteps ...int) *Progress
Config the progress instance
type ProgressFace ¶
type ProgressFace interface {
Start(maxSteps ...int)
Advance(steps ...uint)
AdvanceTo(step uint)
Finish(msg ...string)
Bound() interface{}
}
ProgressFace interface
type RoundTripBar ¶
RoundTripBar config
func (RoundTripBar) Create ¶
func (rt RoundTripBar) Create(maxSteps ...int) *Progress
Create Progress bar from RoundTripBar config.
type WidgetFunc ¶
WidgetFunc handler func for progress widget
func DynamicTextWidget ¶
func DynamicTextWidget(messages map[int]string) WidgetFunc
DynamicTextWidget dynamic text message widget for progress bar. for param messages: int is percent, range is 0 - 100. value is message string. Usage please example.
Example ¶
widget := DynamicTextWidget(map[int]string{
// int is percent, range is 0 - 100.
20: " Prepare ...",
40: " Request ...",
65: " Transport ...",
95: " Saving ...",
100: " Handle Complete.",
})
maxStep := 105
p := New(maxStep).Config(func(p *Progress) {
p.Format = "{@percent:4s}%({@current}/{@max}) {@message}"
}).AddWidget("message", widget)
runProgressBar(p, maxStep, 80)
p.Finish()
func LoadingWidget ¶
func LoadingWidget(chars []rune) WidgetFunc
LoadingWidget create a loading progress widget
func ProgressBarWidget ¶
func ProgressBarWidget(width int, cs BarChars) WidgetFunc
ProgressBarWidget create a progress bar widget.
Output like `[==============>-------------]`
func RoundTripWidget ¶
func RoundTripWidget(char rune, charNum, boxWidth int) WidgetFunc
RoundTripWidget create a round-trip widget for progress bar.
Output like `[ ==== ]`