examples use v5
Vladimir Bauer
6 years ago
| 0 | 0 | module github.com/vbauerster/mpb/_examples/barExtender |
| 1 | 1 | |
| 2 | go 1.13 | |
| 2 | go 1.14 | |
| 3 | 3 | |
| 4 | require github.com/vbauerster/mpb/v4 v4.12.0 | |
| 4 | require github.com/vbauerster/mpb/v5 v5.0.0 | |
| 5 | ||
| 6 | replace github.com/vbauerster/mpb/v5 => /Users/vbauer/gohack/github.com/vbauerster/mpb/v5 |
| 6 | 6 | "sync" |
| 7 | 7 | "time" |
| 8 | 8 | |
| 9 | "github.com/vbauerster/mpb/v4" | |
| 10 | "github.com/vbauerster/mpb/v4/decor" | |
| 9 | "github.com/vbauerster/mpb/v5" | |
| 10 | "github.com/vbauerster/mpb/v5/decor" | |
| 11 | 11 | ) |
| 12 | 12 | |
| 13 | 13 | func main() { |
| 23 | 23 | fmt.Fprintf(w, "Bar id: %d has been completed\n", s.ID) |
| 24 | 24 | } |
| 25 | 25 | } |
| 26 | bar := p.AddBar(int64(total), mpb.BarExtender(mpb.FillerFunc(efn)), | |
| 26 | bar := p.AddBar(int64(total), mpb.BarExtender(mpb.BarFillerFunc(efn)), | |
| 27 | 27 | mpb.PrependDecorators( |
| 28 | 28 | // simple name decorator |
| 29 | 29 | decor.Name(name), |
| 44 | 44 | rng := rand.New(rand.NewSource(time.Now().UnixNano())) |
| 45 | 45 | max := 100 * time.Millisecond |
| 46 | 46 | for i := 0; i < total; i++ { |
| 47 | // start variable is solely for EWMA calculation | |
| 48 | // EWMA's unit of measure is an iteration's taken time | |
| 47 | 49 | start := time.Now() |
| 48 | 50 | time.Sleep(time.Duration(rng.Intn(10)+1) * max / 10) |
| 49 | // since ewma decorator is used, we need to pass time.Since(start) | |
| 50 | bar.Increment(time.Since(start)) | |
| 51 | bar.Increment() | |
| 52 | // since EWMA based decorator is used, DecoratorEwmaUpdate should be called | |
| 53 | bar.DecoratorEwmaUpdate(time.Since(start)) | |
| 51 | 54 | } |
| 52 | 55 | }() |
| 53 | 56 | } |
| 0 | 0 | module github.com/vbauerster/mpb/_examples/cancel |
| 1 | 1 | |
| 2 | go 1.13 | |
| 2 | go 1.14 | |
| 3 | 3 | |
| 4 | require github.com/vbauerster/mpb/v4 v4.12.0 | |
| 4 | require github.com/vbauerster/mpb/v5 v5.0.0 |
| 6 | 6 | "sync" |
| 7 | 7 | "time" |
| 8 | 8 | |
| 9 | "github.com/vbauerster/mpb/v4" | |
| 10 | "github.com/vbauerster/mpb/v4/decor" | |
| 9 | "github.com/vbauerster/mpb/v5" | |
| 10 | "github.com/vbauerster/mpb/v5/decor" | |
| 11 | 11 | ) |
| 12 | 12 | |
| 13 | 13 | func main() { |
| 38 | 38 | rng := rand.New(rand.NewSource(time.Now().UnixNano())) |
| 39 | 39 | max := 100 * time.Millisecond |
| 40 | 40 | for !bar.Completed() { |
| 41 | // start variable is solely for EWMA calculation | |
| 42 | // EWMA's unit of measure is an iteration's taken time | |
| 41 | 43 | start := time.Now() |
| 42 | 44 | time.Sleep(time.Duration(rng.Intn(10)+1) * max / 10) |
| 43 | // since ewma decorator is used, we need to pass time.Since(start) | |
| 44 | bar.Increment(time.Since(start)) | |
| 45 | bar.Increment() | |
| 46 | // since EWMA based decorator is used, DecoratorEwmaUpdate should be called | |
| 47 | bar.DecoratorEwmaUpdate(time.Since(start)) | |
| 45 | 48 | } |
| 46 | 49 | }() |
| 47 | 50 | } |
| 0 | 0 | module github.com/vbauerster/mpb/_examples/complex |
| 1 | 1 | |
| 2 | go 1.13 | |
| 2 | go 1.14 | |
| 3 | 3 | |
| 4 | require github.com/vbauerster/mpb/v4 v4.12.0 | |
| 4 | require github.com/vbauerster/mpb/v5 v5.0.0 |
| 5 | 5 | "sync" |
| 6 | 6 | "time" |
| 7 | 7 | |
| 8 | "github.com/vbauerster/mpb/v4" | |
| 9 | "github.com/vbauerster/mpb/v4/decor" | |
| 8 | "github.com/vbauerster/mpb/v5" | |
| 9 | "github.com/vbauerster/mpb/v5/decor" | |
| 10 | 10 | ) |
| 11 | 11 | |
| 12 | 12 | func init() { |
| 46 | 46 | job := "\x1b[31;1;4minstalling\x1b[0m" |
| 47 | 47 | // preparing delayed bars |
| 48 | 48 | b := p.AddBar(rand.Int63n(101)+100, |
| 49 | mpb.BarParkTo(bars[i]), | |
| 50 | mpb.BarClearOnComplete(), | |
| 49 | mpb.BarQueueAfter(bars[i]), | |
| 50 | mpb.BarFillerClearOnComplete(), | |
| 51 | 51 | mpb.PrependDecorators( |
| 52 | 52 | decor.Name(task, decor.WC{W: len(task) + 1, C: decor.DidentRight}), |
| 53 | 53 | decor.OnComplete(decor.Name(job, decor.WCSyncSpaceR), "done!"), |
| 66 | 66 | p.Wait() |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | func newTask(wg *sync.WaitGroup, b *mpb.Bar, incrBy int) { | |
| 69 | func newTask(wg *sync.WaitGroup, bar *mpb.Bar, incrBy int) { | |
| 70 | 70 | defer wg.Done() |
| 71 | 71 | max := 100 * time.Millisecond |
| 72 | for !b.Completed() { | |
| 72 | for !bar.Completed() { | |
| 73 | // start variable is solely for EWMA calculation | |
| 74 | // EWMA's unit of measure is an iteration's taken time | |
| 73 | 75 | start := time.Now() |
| 74 | 76 | time.Sleep(time.Duration(rand.Intn(10)+1) * max / 10) |
| 75 | // since ewma decorator is used, we need to pass time.Since(start) | |
| 76 | b.IncrBy(incrBy, time.Since(start)) | |
| 77 | bar.IncrBy(incrBy) | |
| 78 | // we need to call DecoratorEwmaUpdate to fulfill ewma decorator's contract | |
| 79 | bar.DecoratorEwmaUpdate(time.Since(start)) | |
| 77 | 80 | } |
| 78 | 81 | } |
| 0 | 0 | module github.com/vbauerster/mpb/_examples/differentWidth |
| 1 | 1 | |
| 2 | go 1.13 | |
| 2 | go 1.14 | |
| 3 | 3 | |
| 4 | require github.com/vbauerster/mpb/v4 v4.12.0 | |
| 4 | require github.com/vbauerster/mpb/v5 v5.0.0 |
| 5 | 5 | "sync" |
| 6 | 6 | "time" |
| 7 | 7 | |
| 8 | "github.com/vbauerster/mpb/v4" | |
| 9 | "github.com/vbauerster/mpb/v4/decor" | |
| 8 | "github.com/vbauerster/mpb/v5" | |
| 9 | "github.com/vbauerster/mpb/v5/decor" | |
| 10 | 10 | ) |
| 11 | 11 | |
| 12 | 12 | func main() { |
| 44 | 44 | rng := rand.New(rand.NewSource(time.Now().UnixNano())) |
| 45 | 45 | max := 100 * time.Millisecond |
| 46 | 46 | for i := 0; i < total; i++ { |
| 47 | // start variable is solely for EWMA calculation | |
| 48 | // EWMA's unit of measure is an iteration's taken time | |
| 47 | 49 | start := time.Now() |
| 48 | 50 | time.Sleep(time.Duration(rng.Intn(10)+1) * max / 10) |
| 49 | // since ewma decorator is used, we need to pass time.Since(start) | |
| 50 | bar.Increment(time.Since(start)) | |
| 51 | bar.Increment() | |
| 52 | // we need to call DecoratorEwmaUpdate to fulfill ewma decorator's contract | |
| 53 | bar.DecoratorEwmaUpdate(time.Since(start)) | |
| 51 | 54 | } |
| 52 | 55 | }() |
| 53 | 56 | } |
| 0 | 0 | module github.com/vbauerster/mpb/_examples/dynTotal |
| 1 | 1 | |
| 2 | go 1.13 | |
| 2 | go 1.14 | |
| 3 | 3 | |
| 4 | require github.com/vbauerster/mpb/v4 v4.12.0 | |
| 4 | require github.com/vbauerster/mpb/v5 v5.0.0 |
| 4 | 4 | "math/rand" |
| 5 | 5 | "time" |
| 6 | 6 | |
| 7 | "github.com/vbauerster/mpb/v4" | |
| 8 | "github.com/vbauerster/mpb/v4/decor" | |
| 7 | "github.com/vbauerster/mpb/v5" | |
| 8 | "github.com/vbauerster/mpb/v5/decor" | |
| 9 | 9 | ) |
| 10 | 10 | |
| 11 | 11 | func init() { |
| 0 | 0 | module github.com/vbauerster/mpb/_examples/io |
| 1 | 1 | |
| 2 | go 1.13 | |
| 2 | go 1.14 | |
| 3 | 3 | |
| 4 | require github.com/vbauerster/mpb/v4 v4.12.0 | |
| 4 | require github.com/vbauerster/mpb/v5 v5.0.0 |
| 5 | 5 | "io/ioutil" |
| 6 | 6 | "time" |
| 7 | 7 | |
| 8 | "github.com/vbauerster/mpb/v4" | |
| 9 | "github.com/vbauerster/mpb/v4/decor" | |
| 8 | "github.com/vbauerster/mpb/v5" | |
| 9 | "github.com/vbauerster/mpb/v5/decor" | |
| 10 | 10 | ) |
| 11 | 11 | |
| 12 | 12 | func main() { |
| 0 | 0 | module github.com/vbauerster/mpb/_examples/merge |
| 1 | 1 | |
| 2 | go 1.13 | |
| 2 | go 1.14 | |
| 3 | 3 | |
| 4 | require github.com/vbauerster/mpb/v4 v4.12.0 | |
| 4 | require github.com/vbauerster/mpb/v5 v5.0.0 |
| 5 | 5 | "sync" |
| 6 | 6 | "time" |
| 7 | 7 | |
| 8 | "github.com/vbauerster/mpb/v4" | |
| 9 | "github.com/vbauerster/mpb/v4/decor" | |
| 8 | "github.com/vbauerster/mpb/v5" | |
| 9 | "github.com/vbauerster/mpb/v5/decor" | |
| 10 | 10 | ) |
| 11 | 11 | |
| 12 | 12 | func main() { |
| 46 | 46 | rng := rand.New(rand.NewSource(time.Now().UnixNano())) |
| 47 | 47 | max := 100 * time.Millisecond |
| 48 | 48 | for i := 0; i < total; i++ { |
| 49 | // start variable is solely for EWMA calculation | |
| 50 | // EWMA's unit of measure is an iteration's taken time | |
| 49 | 51 | start := time.Now() |
| 50 | 52 | time.Sleep(time.Duration(rng.Intn(10)+1) * max / 10) |
| 51 | // since ewma decorator is used, we need to pass time.Since(start) | |
| 52 | bar.Increment(time.Since(start)) | |
| 53 | bar.Increment() | |
| 54 | // we need to call DecoratorEwmaUpdate to fulfill ewma decorator's contract | |
| 55 | bar.DecoratorEwmaUpdate(time.Since(start)) | |
| 53 | 56 | } |
| 54 | 57 | }() |
| 55 | 58 | } |
| 0 | 0 | module github.com/vbauerster/mpb/_examples/multiBars |
| 1 | 1 | |
| 2 | go 1.13 | |
| 2 | go 1.14 | |
| 3 | 3 | |
| 4 | require github.com/vbauerster/mpb/v4 v4.12.0 | |
| 4 | require github.com/vbauerster/mpb/v5 v5.0.0 |
| 5 | 5 | "sync" |
| 6 | 6 | "time" |
| 7 | 7 | |
| 8 | "github.com/vbauerster/mpb/v4" | |
| 9 | "github.com/vbauerster/mpb/v4/decor" | |
| 8 | "github.com/vbauerster/mpb/v5" | |
| 9 | "github.com/vbauerster/mpb/v5/decor" | |
| 10 | 10 | ) |
| 11 | 11 | |
| 12 | 12 | func main() { |
| 39 | 39 | rng := rand.New(rand.NewSource(time.Now().UnixNano())) |
| 40 | 40 | max := 100 * time.Millisecond |
| 41 | 41 | for i := 0; i < total; i++ { |
| 42 | // start variable is solely for EWMA calculation | |
| 43 | // EWMA's unit of measure is an iteration's taken time | |
| 42 | 44 | start := time.Now() |
| 43 | 45 | time.Sleep(time.Duration(rng.Intn(10)+1) * max / 10) |
| 44 | // since ewma decorator is used, we need to pass time.Since(start) | |
| 45 | bar.Increment(time.Since(start)) | |
| 46 | bar.Increment() | |
| 47 | // we need to call DecoratorEwmaUpdate to fulfill ewma decorator's contract | |
| 48 | bar.DecoratorEwmaUpdate(time.Since(start)) | |
| 46 | 49 | } |
| 47 | 50 | }() |
| 48 | 51 | } |
| 0 | 0 | module github.com/vbauerster/mpb/_examples/panic |
| 1 | 1 | |
| 2 | go 1.13 | |
| 2 | go 1.14 | |
| 3 | 3 | |
| 4 | require github.com/vbauerster/mpb/v4 v4.12.0 | |
| 4 | require github.com/vbauerster/mpb/v5 v5.0.0 |
| 5 | 5 | "sync" |
| 6 | 6 | "time" |
| 7 | 7 | |
| 8 | "github.com/vbauerster/mpb/v4" | |
| 9 | "github.com/vbauerster/mpb/v4/decor" | |
| 8 | "github.com/vbauerster/mpb/v5" | |
| 9 | "github.com/vbauerster/mpb/v5/decor" | |
| 10 | 10 | ) |
| 11 | 11 | |
| 12 | 12 | func main() { |
| 0 | 0 | module github.com/vbauerster/mpb/_examples/poplog |
| 1 | 1 | |
| 2 | go 1.13 | |
| 2 | go 1.14 | |
| 3 | 3 | |
| 4 | require github.com/vbauerster/mpb/v4 v4.12.0 | |
| 4 | require github.com/vbauerster/mpb/v5 v5.0.0 |
| 6 | 6 | "sync" |
| 7 | 7 | "time" |
| 8 | 8 | |
| 9 | "github.com/vbauerster/mpb/v4" | |
| 10 | "github.com/vbauerster/mpb/v4/decor" | |
| 9 | "github.com/vbauerster/mpb/v5" | |
| 10 | "github.com/vbauerster/mpb/v5/decor" | |
| 11 | 11 | ) |
| 12 | 12 | |
| 13 | 13 | func main() { |
| 33 | 33 | rng := rand.New(rand.NewSource(time.Now().UnixNano())) |
| 34 | 34 | max := 100 * time.Millisecond |
| 35 | 35 | for i := 0; i < total; i++ { |
| 36 | // start variable is solely for EWMA calculation | |
| 37 | // EWMA's unit of measure is an iteration's taken time | |
| 36 | 38 | start := time.Now() |
| 37 | 39 | time.Sleep(time.Duration(rng.Intn(10)+1) * max / 10) |
| 38 | bar.Increment(time.Since(start)) | |
| 40 | bar.Increment() | |
| 41 | // we need to call DecoratorEwmaUpdate to fulfill ewma decorator's contract | |
| 42 | bar.DecoratorEwmaUpdate(time.Since(start)) | |
| 39 | 43 | } |
| 40 | 44 | }() |
| 41 | 45 | } |
| 57 | 61 | p.Wait() |
| 58 | 62 | } |
| 59 | 63 | |
| 60 | func makeLogBar(msg string) mpb.Filler { | |
| 64 | func makeLogBar(msg string) mpb.BarFiller { | |
| 61 | 65 | limit := "%%.%ds" |
| 62 | return mpb.FillerFunc(func(w io.Writer, width int, st *decor.Statistics) { | |
| 66 | return mpb.BarFillerFunc(func(w io.Writer, width int, st *decor.Statistics) { | |
| 63 | 67 | fmt.Fprintf(w, fmt.Sprintf(limit, width), msg) |
| 64 | 68 | }) |
| 65 | 69 | } |
| 0 | 0 | module github.com/vbauerster/mpb/_examples/quietMode |
| 1 | 1 | |
| 2 | go 1.13 | |
| 2 | go 1.14 | |
| 3 | 3 | |
| 4 | require github.com/vbauerster/mpb/v4 v4.12.0 | |
| 4 | require github.com/vbauerster/mpb/v5 v5.0.0 |
| 6 | 6 | "sync" |
| 7 | 7 | "time" |
| 8 | 8 | |
| 9 | "github.com/vbauerster/mpb/v4" | |
| 10 | "github.com/vbauerster/mpb/v4/decor" | |
| 9 | "github.com/vbauerster/mpb/v5" | |
| 10 | "github.com/vbauerster/mpb/v5/decor" | |
| 11 | 11 | ) |
| 12 | 12 | |
| 13 | 13 | var quietMode bool |
| 57 | 57 | rng := rand.New(rand.NewSource(time.Now().UnixNano())) |
| 58 | 58 | max := 100 * time.Millisecond |
| 59 | 59 | for i := 0; i < total; i++ { |
| 60 | // start variable is solely for EWMA calculation | |
| 61 | // EWMA's unit of measure is an iteration's taken time | |
| 60 | 62 | start := time.Now() |
| 61 | 63 | time.Sleep(time.Duration(rng.Intn(10)+1) * max / 10) |
| 62 | // since ewma decorator is used, we need to pass time.Since(start) | |
| 63 | bar.Increment(time.Since(start)) | |
| 64 | bar.Increment() | |
| 65 | // we need to call DecoratorEwmaUpdate to fulfill ewma decorator's contract | |
| 66 | bar.DecoratorEwmaUpdate(time.Since(start)) | |
| 64 | 67 | } |
| 65 | 68 | }() |
| 66 | 69 | } |
| 0 | 0 | module github.com/vbauerster/mpb/_examples/remove |
| 1 | 1 | |
| 2 | go 1.13 | |
| 2 | go 1.14 | |
| 3 | 3 | |
| 4 | require github.com/vbauerster/mpb/v4 v4.12.0 | |
| 4 | require github.com/vbauerster/mpb/v5 v5.0.0 |
| 5 | 5 | "sync" |
| 6 | 6 | "time" |
| 7 | 7 | |
| 8 | "github.com/vbauerster/mpb/v4" | |
| 9 | "github.com/vbauerster/mpb/v4/decor" | |
| 8 | "github.com/vbauerster/mpb/v5" | |
| 9 | "github.com/vbauerster/mpb/v5/decor" | |
| 10 | 10 | ) |
| 11 | 11 | |
| 12 | 12 | func main() { |
| 18 | 18 | |
| 19 | 19 | for i := 0; i < numBars; i++ { |
| 20 | 20 | name := fmt.Sprintf("Bar#%d:", i) |
| 21 | b := p.AddBar(int64(total), mpb.BarID(i), | |
| 21 | bar := p.AddBar(int64(total), | |
| 22 | mpb.BarID(i), | |
| 22 | 23 | mpb.BarOptOn(mpb.BarRemoveOnComplete(), func() bool { return i == 0 }), |
| 23 | 24 | mpb.PrependDecorators( |
| 24 | 25 | decor.Name(name), |
| 30 | 31 | defer wg.Done() |
| 31 | 32 | rng := rand.New(rand.NewSource(time.Now().UnixNano())) |
| 32 | 33 | max := 100 * time.Millisecond |
| 33 | for i := 0; !b.Completed(); i++ { | |
| 34 | for i := 0; !bar.Completed(); i++ { | |
| 35 | // start variable is solely for EWMA calculation | |
| 36 | // EWMA's unit of measure is an iteration's taken time | |
| 34 | 37 | start := time.Now() |
| 35 | if b.ID() == 2 && i >= 42 { | |
| 38 | if bar.ID() == 2 && i >= 42 { | |
| 36 | 39 | // aborting and removing while bar is running |
| 37 | b.Abort(true) | |
| 40 | bar.Abort(true) | |
| 38 | 41 | } |
| 39 | 42 | time.Sleep(time.Duration(rng.Intn(10)+1) * max / 10) |
| 40 | // since ewma decorator is used, we need to pass time.Since(start) | |
| 41 | b.Increment(time.Since(start)) | |
| 43 | bar.Increment() | |
| 44 | // we need to call DecoratorEwmaUpdate to fulfill ewma decorator's contract | |
| 45 | bar.DecoratorEwmaUpdate(time.Since(start)) | |
| 42 | 46 | } |
| 43 | 47 | }() |
| 44 | 48 | } |
| 0 | 0 | module github.com/vbauerster/mpb/_examples/reverseBar |
| 1 | 1 | |
| 2 | go 1.13 | |
| 2 | go 1.14 | |
| 3 | 3 | |
| 4 | require github.com/vbauerster/mpb/v4 v4.12.0 | |
| 4 | require github.com/vbauerster/mpb/v5 v5.0.0 |
| 5 | 5 | "sync" |
| 6 | 6 | "time" |
| 7 | 7 | |
| 8 | "github.com/vbauerster/mpb/v4" | |
| 9 | "github.com/vbauerster/mpb/v4/decor" | |
| 8 | "github.com/vbauerster/mpb/v5" | |
| 9 | "github.com/vbauerster/mpb/v5/decor" | |
| 10 | 10 | ) |
| 11 | 11 | |
| 12 | 12 | func main() { |
| 41 | 41 | rng := rand.New(rand.NewSource(time.Now().UnixNano())) |
| 42 | 42 | max := 100 * time.Millisecond |
| 43 | 43 | for i := 0; i < total; i++ { |
| 44 | // start variable is solely for EWMA calculation | |
| 45 | // EWMA's unit of measure is an iteration's taken time | |
| 44 | 46 | start := time.Now() |
| 45 | 47 | time.Sleep(time.Duration(rng.Intn(10)+1) * max / 10) |
| 46 | // since ewma decorator is used, we need to pass time.Since(start) | |
| 47 | bar.Increment(time.Since(start)) | |
| 48 | bar.Increment() | |
| 49 | // we need to call DecoratorEwmaUpdate to fulfill ewma decorator's contract | |
| 50 | bar.DecoratorEwmaUpdate(time.Since(start)) | |
| 48 | 51 | } |
| 49 | 52 | }() |
| 50 | 53 | } |
| 0 | 0 | module github.com/vbauerster/mpb/_examples/singleBar |
| 1 | 1 | |
| 2 | go 1.13 | |
| 2 | go 1.14 | |
| 3 | 3 | |
| 4 | require github.com/vbauerster/mpb/v4 v4.12.0 | |
| 4 | require github.com/vbauerster/mpb/v5 v5.0.0 |
| 3 | 3 | "math/rand" |
| 4 | 4 | "time" |
| 5 | 5 | |
| 6 | "github.com/vbauerster/mpb/v4" | |
| 7 | "github.com/vbauerster/mpb/v4/decor" | |
| 6 | "github.com/vbauerster/mpb/v5" | |
| 7 | "github.com/vbauerster/mpb/v5/decor" | |
| 8 | 8 | ) |
| 9 | 9 | |
| 10 | 10 | func main() { |
| 31 | 31 | // simulating some work |
| 32 | 32 | max := 100 * time.Millisecond |
| 33 | 33 | for i := 0; i < total; i++ { |
| 34 | // start variable is solely for EWMA calculation | |
| 35 | // EWMA's unit of measure is an iteration's taken time | |
| 34 | 36 | start := time.Now() |
| 35 | 37 | time.Sleep(time.Duration(rand.Intn(10)+1) * max / 10) |
| 36 | // since ewma decorator is used, we need to pass time.Since(start) | |
| 37 | bar.Increment(time.Since(start)) | |
| 38 | bar.Increment() | |
| 39 | // we need to call DecoratorEwmaUpdate to fulfill ewma decorator's contract | |
| 40 | bar.DecoratorEwmaUpdate(time.Since(start)) | |
| 38 | 41 | } |
| 39 | 42 | // wait for our bar to complete and flush |
| 40 | 43 | p.Wait() |
| 0 | 0 | module github.com/vbauerster/mpb/_examples/spinnerBar |
| 1 | 1 | |
| 2 | go 1.13 | |
| 2 | go 1.14 | |
| 3 | 3 | |
| 4 | require github.com/vbauerster/mpb/v4 v4.12.0 | |
| 4 | require github.com/vbauerster/mpb/v5 v5.0.0 |
| 5 | 5 | "sync" |
| 6 | 6 | "time" |
| 7 | 7 | |
| 8 | "github.com/vbauerster/mpb/v4" | |
| 9 | "github.com/vbauerster/mpb/v4/decor" | |
| 8 | "github.com/vbauerster/mpb/v5" | |
| 9 | "github.com/vbauerster/mpb/v5/decor" | |
| 10 | 10 | ) |
| 11 | 11 | |
| 12 | 12 | func main() { |
| 0 | 0 | module github.com/vbauerster/mpb/_examples/spinnerDecorator |
| 1 | 1 | |
| 2 | go 1.13 | |
| 2 | go 1.14 | |
| 3 | 3 | |
| 4 | require github.com/vbauerster/mpb/v4 v4.12.0 | |
| 4 | require github.com/vbauerster/mpb/v5 v5.0.0 |
| 5 | 5 | "sync" |
| 6 | 6 | "time" |
| 7 | 7 | |
| 8 | "github.com/vbauerster/mpb/v4" | |
| 9 | "github.com/vbauerster/mpb/v4/decor" | |
| 8 | "github.com/vbauerster/mpb/v5" | |
| 9 | "github.com/vbauerster/mpb/v5/decor" | |
| 10 | 10 | ) |
| 11 | 11 | |
| 12 | 12 | func main() { |
| 0 | 0 | module github.com/vbauerster/mpb/_examples/stress |
| 1 | 1 | |
| 2 | go 1.13 | |
| 2 | go 1.14 | |
| 3 | 3 | |
| 4 | require github.com/vbauerster/mpb/v4 v4.12.0 | |
| 4 | require github.com/vbauerster/mpb/v5 v5.0.0 |
| 5 | 5 | "sync" |
| 6 | 6 | "time" |
| 7 | 7 | |
| 8 | "github.com/vbauerster/mpb/v4" | |
| 9 | "github.com/vbauerster/mpb/v4/decor" | |
| 8 | "github.com/vbauerster/mpb/v5" | |
| 9 | "github.com/vbauerster/mpb/v5/decor" | |
| 10 | 10 | ) |
| 11 | 11 | |
| 12 | 12 | const ( |
| 0 | 0 | module github.com/vbauerster/mpb/_examples/suppressBar |
| 1 | 1 | |
| 2 | go 1.13 | |
| 2 | go 1.14 | |
| 3 | 3 | |
| 4 | require github.com/vbauerster/mpb/v4 v4.12.0 | |
| 4 | require github.com/vbauerster/mpb/v5 v5.0.0 |
| 7 | 7 | "sync" |
| 8 | 8 | "time" |
| 9 | 9 | |
| 10 | "github.com/vbauerster/mpb/v4" | |
| 11 | "github.com/vbauerster/mpb/v4/decor" | |
| 10 | "github.com/vbauerster/mpb/v5" | |
| 11 | "github.com/vbauerster/mpb/v5/decor" | |
| 12 | 12 | ) |
| 13 | 13 | |
| 14 | 14 | func main() { |
| 75 | 75 | ew.Unlock() |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | type customFiller struct { | |
| 79 | mpb.Filler | |
| 80 | base mpb.Filler | |
| 78 | type myBarFiller struct { | |
| 79 | mpb.BarFiller | |
| 80 | base mpb.BarFiller | |
| 81 | 81 | } |
| 82 | 82 | |
| 83 | // implementing mpb.WrapFiller, so bar.SetRefill works | |
| 84 | func (cf *customFiller) Base() mpb.Filler { | |
| 83 | func (cf *myBarFiller) Base() mpb.BarFiller { | |
| 85 | 84 | return cf.base |
| 86 | 85 | } |
| 87 | 86 | |
| 88 | func newCustomFiller(ch <-chan string, resume <-chan struct{}) (mpb.Filler, <-chan struct{}) { | |
| 87 | func newCustomFiller(ch <-chan string, resume <-chan struct{}) (mpb.BarFiller, <-chan struct{}) { | |
| 89 | 88 | base := mpb.NewBarFiller(mpb.DefaultBarStyle, false) |
| 90 | 89 | nextCh := make(chan struct{}, 1) |
| 91 | 90 | var msg *string |
| 92 | filler := func(w io.Writer, width int, st *decor.Statistics) { | |
| 91 | filler := mpb.BarFillerFunc(func(w io.Writer, width int, st *decor.Statistics) { | |
| 93 | 92 | select { |
| 94 | 93 | case m := <-ch: |
| 95 | 94 | defer func() { |
| 107 | 106 | } else { |
| 108 | 107 | base.Fill(w, width, st) |
| 109 | 108 | } |
| 110 | } | |
| 111 | cf := &customFiller{ | |
| 112 | Filler: mpb.FillerFunc(filler), | |
| 113 | base: base, | |
| 109 | }) | |
| 110 | cf := &myBarFiller{ | |
| 111 | BarFiller: filler, | |
| 112 | base: base, | |
| 114 | 113 | } |
| 115 | 114 | return cf, nextCh |
| 116 | 115 | } |