From 854f5d5e7abd31afa118fe9b09d3d164b7c61ff8 Mon Sep 17 00:00:00 2001 From: Eiko Thomas <13103714+OkieOth@users.noreply.github.com> Date: Sun, 12 Jan 2025 18:22:29 +0100 Subject: [PATCH] add simple spinner/counter example --- examples/counter/main.go | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 examples/counter/main.go diff --git a/examples/counter/main.go b/examples/counter/main.go new file mode 100644 index 0000000..d8c8dfa --- /dev/null +++ b/examples/counter/main.go @@ -0,0 +1,35 @@ +package main + +import ( + "github.com/schollz/progressbar/v3" + "time" +) + +// This example illustrates a simple spinner that displays the number of +// received calls +func main() { + bar := progressbar.NewOptions64( + -1, + progressbar.OptionSetDescription("[Counter Example] Received"), + progressbar.OptionSetWidth(10), + progressbar.OptionThrottle(65*time.Millisecond), + progressbar.OptionShowCount(), + progressbar.OptionSpinnerType(14), + progressbar.OptionFullWidth(), + progressbar.OptionSetRenderBlankState(true), + ) + + c := make(chan int) + + go func(notify chan<- int) { + defer close(notify) + for i := 0; i < 100; i++ { + c <- i + time.Sleep(time.Millisecond * 100) + } + }(c) + + for v := range c { + bar.Add(v) + } +}