-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathopts.go
122 lines (102 loc) · 2.15 KB
/
opts.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
// Copyright © 2022 Atonal Authors
//
package progressbar
import "io"
type Opt func(pb *pbar)
func WithBarSpinner(whichOne int) Opt {
return func(pb *pbar) {
if s, ok := spinners[whichOne]; ok {
pb.stepper = s.init()
}
}
}
func WithBarStepper(whichOne int) Opt {
return func(pb *pbar) {
if s, ok := steppers[whichOne]; ok {
pb.stepper = s.init()
}
}
}
func WithBarStepperPostInit(cb func(bar BarT)) Opt {
return func(pb *pbar) {
pb.stepperPostInit = cb
}
}
func WithBarUpperBound(ub int64) Opt {
return func(pb *pbar) {
pb.max = ub
}
}
func WithBarWidth(w int) Opt {
return func(pb *pbar) {
pb.stepper.SetWidth(w)
}
}
// WithBarTextSchema allows cha
//
// "{{.Indent}}{{.Prepend}} {{.Bar}} {{.Percent}} | {{.Title}} | {{.Current}}/{{.Total}} {{.Speed}} {{.Elapsed}} {{.Append}}"
func WithBarTextSchema(schema string) Opt {
return func(pb *pbar) {
pb.stepper.SetSchema(schema)
}
}
func WithBarIndentChars(str string) Opt {
return func(pb *pbar) {
pb.stepper.SetIndentChars(str)
}
}
func WithBarPrependText(str string) Opt {
return func(pb *pbar) {
pb.stepper.SetPrependText(str)
}
}
func WithBarAppendText(str string) Opt {
return func(pb *pbar) {
pb.stepper.SetAppendText(str)
}
}
// WithBarExtraTailSpaces specifies how many spaces will be printed
// at end of each bar. These spaces can wipe out the dirty tail of
// line.
//
// Default is 8 (spaces). You may specify -1 to disable extra
// spaces to be printed.
func WithBarExtraTailSpaces(howMany int) Opt {
return func(pb *pbar) {
pb.stepper.SetExtraTailSpaces(howMany)
}
}
func WithBarWorker(w Worker) Opt {
return func(pb *pbar) {
pb.worker = w
}
}
func WithBarOnCompleted(cb OnCompleted) Opt {
return func(pb *pbar) {
pb.onComp = cb
}
}
func WithBarOnStart(cb OnStart) Opt {
return func(pb *pbar) {
pb.onStart = cb
}
}
func WithBarOnDataPrepared(cb OnDataPrepared) Opt {
return func(pb *pbar) {
pb.onDataPrepared = cb
}
}
type (
OnDone func(mpb MultiPB)
MOpt func(mpb *mpbar)
)
func WithOnDone(cb OnDone) MOpt {
return func(mpb *mpbar) {
mpb.onDone = cb
}
}
func WithOutputDevice(out io.Writer) MOpt {
return func(mpb *mpbar) {
mpb.out = out
}
}