forked from schollz/progressbar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
41 lines (35 loc) · 883 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package main
import (
"fmt"
"time"
"github.com/k0kubun/go-ansi"
"github.com/schollz/progressbar/v3"
)
func main() {
doneCh := make(chan struct{})
bar := progressbar.NewOptions(1000,
progressbar.OptionSetWriter(ansi.NewAnsiStdout()),
progressbar.OptionEnableColorCodes(true),
progressbar.OptionSetWidth(50),
progressbar.OptionSetTheme(progressbar.Theme{
Saucer: " ",
AltSaucerHead: "[yellow]<[reset]",
SaucerHead: "[yellow]-[reset]",
SaucerPadding: "[white]•",
BarStart: "[blue]|[reset]",
BarEnd: "[blue]|[reset]",
}),
progressbar.OptionOnCompletion(func() {
doneCh <- struct{}{}
}),
)
go func() {
for i := 0; i < 1000; i++ {
bar.Add(1)
time.Sleep(10 * time.Millisecond)
}
}()
// got notified that progress bar is complete.
<-doneCh
fmt.Println("\n ======= progress bar completed ==========\n")
}