diff --git a/doc.go b/doc.go new file mode 100644 index 0000000..5ada717 --- /dev/null +++ b/doc.go @@ -0,0 +1,2 @@ +// Package mpb is a library for rendering progress bars in terminal applications. +package mpb diff --git a/example_test.go b/example_test.go new file mode 100644 index 0000000..dff4594 --- /dev/null +++ b/example_test.go @@ -0,0 +1,27 @@ +package mpb_test + +import ( + "math/rand" + "time" + + "github.com/vbauerster/mpb" +) + +func Example() { + // Star mpb's rendering goroutine. + // If you don't plan to cancel, feed with nil + // otherwise provide context.Context, see cancel example + p := mpb.New(nil) + // Set custom format, the default one is "[=>-]" + p.Format("╢▌▌░╟") + + bar := p.AddBar(100).PrependName("Single Bar:", 0).AppendPercentage() + + for i := 0; i < 100; i++ { + time.Sleep(time.Duration(rand.Intn(100)) * time.Millisecond) + bar.Incr(1) + } + + // Don't forget to stop mpb's rendering goroutine + p.Stop() +}