modulepackage
0.0.0-20181013131528-0306ae9a87d1
Repository: https://github.com/nu11ptr/cmpb.git
Documentation: pkg.go.dev
# README
cmpb
A color multi-progress bar for Go terminal applications. Works on ANSI compatible terminals... and also on Windows!
Demo
Demo Source
package main
import (
"math/rand"
"time"
"github.com/fatih/color"
"github.com/nu11ptr/cmpb"
)
const total = 100
var (
keys = []string{"server1000", "server1001", "server1002"}
actions = []string{"downloading...", "compiling source...", "fetching...", "committing work..."}
)
func main() {
p := cmpb.New()
colors := new(cmpb.BarColors)
colors.Post, colors.KeyDiv, colors.LBracket, colors.RBracket =
color.HiCyanString, color.HiCyanString, color.HiCyanString, color.HiCyanString
colors.Key = color.HiBlueString
colors.Msg, colors.Empty = color.HiYellowString, color.HiYellowString
colors.Full = color.HiGreenString
colors.Curr = color.GreenString
colors.PreBar, colors.PostBar = color.HiMagentaString, color.HiMagentaString
for _, key := range keys {
b := p.NewBar(key, total)
go func() {
for i := 0; i < total; i++ {
time.Sleep(time.Duration(rand.Intn(250)) * time.Millisecond)
action := actions[rand.Intn(len(actions))]
b.SetMessage(action)
b.Increment()
}
}()
}
p.SetColors(colors)
p.Start()
p.Wait()
}
# Packages
No description provided by the author
# Functions
AnsiScrollUp uses ANSI escape codes to do the scroll up action.
CalcDur calculates the duration since start time and returns a string.
CalcPct calculates the percentage of work complete and returns as a string.
CalcSteps calculates the steps completed so far and returns a string.
DefaultColors returns a set of default colors for rendering the bar.
DefaultParam builds a Param struct with default values.
New creates a new progress bar collection with default params.
NewWithParam creates a new progress bar collection with specified params.