Skip to content

Commit 854f5d5

Browse files
committed
add simple spinner/counter example
1 parent 6e18d11 commit 854f5d5

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

examples/counter/main.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package main
2+
3+
import (
4+
"github.com/schollz/progressbar/v3"
5+
"time"
6+
)
7+
8+
// This example illustrates a simple spinner that displays the number of
9+
// received calls
10+
func main() {
11+
bar := progressbar.NewOptions64(
12+
-1,
13+
progressbar.OptionSetDescription("[Counter Example] Received"),
14+
progressbar.OptionSetWidth(10),
15+
progressbar.OptionThrottle(65*time.Millisecond),
16+
progressbar.OptionShowCount(),
17+
progressbar.OptionSpinnerType(14),
18+
progressbar.OptionFullWidth(),
19+
progressbar.OptionSetRenderBlankState(true),
20+
)
21+
22+
c := make(chan int)
23+
24+
go func(notify chan<- int) {
25+
defer close(notify)
26+
for i := 0; i < 100; i++ {
27+
c <- i
28+
time.Sleep(time.Millisecond * 100)
29+
}
30+
}(c)
31+
32+
for v := range c {
33+
bar.Add(v)
34+
}
35+
}

0 commit comments

Comments
 (0)