Package doc
Vladimir Bauer
9 years ago
| 0 | package mpb_test | |
| 1 | ||
| 2 | import ( | |
| 3 | "math/rand" | |
| 4 | "time" | |
| 5 | ||
| 6 | "github.com/vbauerster/mpb" | |
| 7 | ) | |
| 8 | ||
| 9 | func Example() { | |
| 10 | // Star mpb's rendering goroutine. | |
| 11 | // If you don't plan to cancel, feed with nil | |
| 12 | // otherwise provide context.Context, see cancel example | |
| 13 | p := mpb.New(nil) | |
| 14 | // Set custom format, the default one is "[=>-]" | |
| 15 | p.Format("╢▌▌░╟") | |
| 16 | ||
| 17 | bar := p.AddBar(100).PrependName("Single Bar:", 0).AppendPercentage() | |
| 18 | ||
| 19 | for i := 0; i < 100; i++ { | |
| 20 | time.Sleep(time.Duration(rand.Intn(100)) * time.Millisecond) | |
| 21 | bar.Incr(1) | |
| 22 | } | |
| 23 | ||
| 24 | // Don't forget to stop mpb's rendering goroutine | |
| 25 | p.Stop() | |
| 26 | } |