Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Bar ¶
type Bar interface {
UpdateDisplay(newDisplay *DisplayProps)
}
Bar controls how a bar is displayed, for both single bar or multi bar item.
type DisplayProps ¶
type DisplayProps struct { Prefix string `json:"prefix,omitempty"` Suffix string `json:"suffix,omitempty"` // If `Mode == Done / Error`, Suffix is not printed Mode Mode `json:"mode,omitempty"` Detail string `json:"detail,omitempty"` }
DisplayProps controls the display of the progress bar.
type Mode ¶
type Mode int
Mode determines how the progress bar is rendered
func (Mode) MarshalJSON ¶
MarshalJSON implements JSON marshaler
func (*Mode) UnmarshalJSON ¶
UnmarshalJSON implements JSON unmarshaler
type MultiBar ¶
type MultiBar struct {
// contains filtered or unexported fields
}
MultiBar renders multiple progress bars.
func (*MultiBar) AddBar ¶
func (b *MultiBar) AddBar(prefix string) *MultiBarItem
AddBar adds a new bar item. This function is not thread safe. Must be called before render loop is started.
func (*MultiBar) StartRenderLoop ¶
func (b *MultiBar) StartRenderLoop()
StartRenderLoop starts the render loop. This function is thread safe.
func (*MultiBar) StopRenderLoop ¶
func (b *MultiBar) StopRenderLoop()
StopRenderLoop stops the render loop. This function is thread safe.
type MultiBarItem ¶
type MultiBarItem struct {
// contains filtered or unexported fields
}
MultiBarItem controls a bar item inside MultiBar.
func (*MultiBarItem) UpdateDisplay ¶
func (i *MultiBarItem) UpdateDisplay(newDisplay *DisplayProps)
UpdateDisplay updates the display property of this bar item. This function is thread safe.
type SingleBar ¶
type SingleBar struct {
// contains filtered or unexported fields
}
SingleBar renders single progress bar.
Example ¶
package main import ( "strconv" "time" "github.com/wentaojin/dbms/utils/progress" ) func main() { b := progress.NewSingleBar("Prefix") b.UpdateDisplay(&progress.DisplayProps{ Prefix: "Prefix", Suffix: "Suffix", }) n := 3 go func() { time.Sleep(time.Second) for i := 0; i < n; i++ { b.UpdateDisplay(&progress.DisplayProps{ Prefix: "Prefix" + strconv.Itoa(i), Suffix: "Suffix" + strconv.Itoa(i), }) time.Sleep(time.Second) } }() b.StartRenderLoop() time.Sleep(time.Second * time.Duration(n+1)) b.UpdateDisplay(&progress.DisplayProps{ Mode: progress.ModeDone, // Mode: progress.ModeError, Prefix: "Prefix", }) b.StopRenderLoop() }
Output:
Example (Err) ¶
package main import ( "errors" "strconv" "time" "github.com/wentaojin/dbms/utils/progress" ) func main() { b := progress.NewSingleBar("Prefix") b.UpdateDisplay(&progress.DisplayProps{ Prefix: "Prefix", Suffix: "Suffix", }) n := 3 go func() { time.Sleep(time.Second) for i := 0; i < n; i++ { b.UpdateDisplay(&progress.DisplayProps{ Prefix: "Prefix" + strconv.Itoa(i), Suffix: "Suffix" + strconv.Itoa(i), }) time.Sleep(time.Second) } }() b.StartRenderLoop() time.Sleep(time.Second * time.Duration(n+1)) b.UpdateDisplay(&progress.DisplayProps{ Mode: progress.ModeError, Prefix: "Prefix", Detail: errors.New("expected failure").Error(), }) b.StopRenderLoop() }
Output:
func NewSingleBar ¶
NewSingleBar creates a new SingleBar.
func (*SingleBar) StartRenderLoop ¶
func (b *SingleBar) StartRenderLoop()
StartRenderLoop starts the render loop. This function is thread safe.
func (*SingleBar) StopRenderLoop ¶
func (b *SingleBar) StopRenderLoop()
StopRenderLoop stops the render loop. This function is thread safe.
func (*SingleBar) UpdateDisplay ¶
func (b *SingleBar) UpdateDisplay(newDisplay *DisplayProps)
UpdateDisplay updates the display property of this single bar. This function is thread safe.