-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogressbar.go
More file actions
48 lines (41 loc) · 976 Bytes
/
progressbar.go
File metadata and controls
48 lines (41 loc) · 976 Bytes
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
package ProgressBar
import (
"fmt"
"github.com/tianyazc/zlxGo/zlxmodule/color"
"os"
"strings"
)
type ProgressBar struct {
typestr string
count int
syncs chan int
color color.Color
}
func NewPb() *ProgressBar {
return &ProgressBar{
syncs: make(chan int),
}
}
func (pb *ProgressBar) Bar(describe, typestr string, count int) {
go pb.BarOut(describe, typestr, count)
}
func (pb *ProgressBar) BarOut(describe, typestr string, count int) {
_, _ = fmt.Fprintln(os.Stdout, describe)
pb.out(typestr, count)
_, _ = fmt.Fprintf(os.Stdout, "\n")
}
func (pb *ProgressBar) out(typestr string, count int) {
for i := 0; i <= count; i++ {
fill := strings.Repeat(" ", count-i)
tstr := strings.Repeat(typestr, i)
_, _ = fmt.Fprint(os.Stdout, "\r[")
_, _ = fmt.Fprintf(os.Stdout, "%s%s]", tstr, fill)
p := int(i * 100 / count)
_, _ = fmt.Fprintf(os.Stdout, "\t%d %%", p)
pb.syncs <- i
}
}
func (pb *ProgressBar) Complete() {
x := <-pb.syncs
_ = x
}