Skip to content

Commit

Permalink
add simple spinner/counter example
Browse files Browse the repository at this point in the history
  • Loading branch information
OkieOth committed Jan 12, 2025
1 parent 6e18d11 commit 854f5d5
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions examples/counter/main.go
Original file line number Diff line number Diff line change
@@ -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)
}
}

0 comments on commit 854f5d5

Please sign in to comment.