forked from Altinity/clickhouse-backup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpbar.go
66 lines (57 loc) · 914 Bytes
/
pbar.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
54
55
56
57
58
59
60
61
62
63
64
65
66
package main
import (
progressbar "gopkg.in/cheggaaa/pb.v1"
"io"
)
type Bar struct {
pb *progressbar.ProgressBar
show bool
}
func StartNewByteBar(show bool, total int64) *Bar {
if show {
return &Bar{
show: true,
pb: progressbar.StartNew(int(total)).SetUnits(progressbar.U_BYTES),
}
}
return &Bar{
show: false,
}
}
func StartNewBar(show bool, total int) *Bar {
if show {
return &Bar{
show: true,
pb: progressbar.StartNew(total),
}
}
return &Bar{
show: false,
}
}
func (b *Bar) FinishPrint(str string) {
if b.show {
b.pb.FinishPrint(str)
}
}
func (b *Bar) Add64(add int64) {
if b.show {
b.pb.Add64(add)
}
}
func (b *Bar) Set(current int) {
if b.show {
b.pb.Set(current)
}
}
func (b *Bar) Increment() {
if b.show {
b.pb.Increment()
}
}
func (b *Bar) NewProxyReader(r io.Reader) io.Reader {
if b.show {
return b.pb.NewProxyReader(r)
}
return r
}