-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathopts.go
More file actions
148 lines (124 loc) · 2.57 KB
/
opts.go
File metadata and controls
148 lines (124 loc) · 2.57 KB
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
// Copyright © 2022 Atonal Authors
//
package progressbar
import (
"io"
)
type Opt func(pb *pbar)
func WithBarDelayedStart(delayed bool) Opt {
return func(pb *pbar) {
pb.SetDelayedStart(delayed)
}
}
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)
}
}
func WithBarInitialValue(v int64) Opt {
return func(pb *pbar) {
pb.stepper.SetInitialValue(v)
}
}
func WithBarResumeable(b bool) Opt {
return func(pb *pbar) {
pb.stepper.SetResumeable(b)
}
}
// 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
}
}
// func WithBarLogger(logger *slog.Logger) Opt {
// return func(pb *pbar) {
// pb.logger = logger
// }
// }
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
}
}