-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
53 lines (45 loc) · 981 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
42
43
44
45
46
47
48
49
50
51
52
53
package main
import (
"math/rand"
"os"
"time"
"github.com/mandelsoft/ttyprogress"
"github.com/mandelsoft/ttyprogress/synclog"
)
func Step(n string) ttyprogress.NestedStep {
return ttyprogress.NewNestedStep[ttyprogress.Bar](
n, ttyprogress.NewBar().SetTotal(100).
// HideOnClose().
PrependElapsed().
AppendCompleted(),
)
}
func main() {
synclog.LogToFile("local/lock.log")
p := ttyprogress.For(os.Stdout)
bar, _ := ttyprogress.NewNestedSteps(
Step("downloading"),
Step("unpacking"),
Step("installing"),
Step("verifying")).
SetGap(" ").
SetWidth(40).
ShowStepTitle(false).
PrependFunc(ttyprogress.Message("progressbar"), 0).
PrependElapsed().
AppendCompleted().
Add(p)
p.Close()
go func() {
bar.Start()
e := bar.Current()
for i := 0; i < 4; i++ {
for i := 0; i < 100; i++ {
time.Sleep(time.Millisecond * time.Duration(rand.Int()%100))
e.(ttyprogress.Bar).Incr()
}
e, _ = bar.Incr()
}
}()
p.Wait(nil)
}