diff --git a/example/interrupt/main.go b/example/interrupt/main.go deleted file mode 100644 index e875d0c..0000000 --- a/example/interrupt/main.go +++ /dev/null @@ -1,37 +0,0 @@ -package main - -import ( - "fmt" - "math/rand" - "time" - - "github.com/vbauerster/mpb" -) - -const ( - totalItem = 100 - maxBlockSize = 14 -) - -func main() { - decor := func(s *mpb.Statistics) string { - str := fmt.Sprintf("%d/%d", s.Current, s.Total) - return fmt.Sprintf("%-7s", str) - } - - p := mpb.New() - bar := p.AddBar(totalItem).AppendETA().PrependFunc(decor) - - blockSize := rand.Intn(maxBlockSize) + 1 - for i := 0; bar.InProgress(); i++ { - time.Sleep(time.Duration(blockSize) * (50*time.Millisecond + time.Duration(rand.Intn(5*int(time.Millisecond))))) - bar.Incr(blockSize) - if bar.Current() > 42 && p.RemoveBar(bar) { - break - } - blockSize = rand.Intn(maxBlockSize) + 1 - } - - p.Stop() - fmt.Println("stop") -} diff --git a/example/singleBar/e.txt b/example/singleBar/e.txt new file mode 100644 index 0000000..e69de29 diff --git a/example/singleBar/main.go b/example/singleBar/main.go new file mode 100644 index 0000000..18dc43b --- /dev/null +++ b/example/singleBar/main.go @@ -0,0 +1,34 @@ +package main + +import ( + "fmt" + "math/rand" + "time" + + "github.com/vbauerster/mpb" +) + +const ( + totalItem = 100 + maxBlockSize = 10 +) + +func main() { + + name := "Single:" + p := mpb.New() + bar := p.AddBar(totalItem). + PrependName(name, 0). + AppendPercentage(). + TrimRightSpace() + + blockSize := rand.Intn(maxBlockSize) + 1 + for i := 0; i < totalItem; i++ { + time.Sleep(time.Duration(blockSize) * (50*time.Millisecond + time.Duration(rand.Intn(5*int(time.Millisecond))))) + bar.Incr(1) + blockSize = rand.Intn(maxBlockSize) + 1 + } + + p.Stop() + fmt.Println("stop") +}