forked from d3mondev/puredns
-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.go
64 lines (49 loc) · 1.18 KB
/
options.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
package progressbar
import (
"io"
"time"
)
// Option configures a progress bar.
type Option interface {
apply(*options)
}
type options struct {
updateInterval time.Duration
template string
writer io.Writer
style Style
}
// WithTemplate provides a template string to the progress bar.
func WithTemplate(t string) Option {
return templateOption(t)
}
type templateOption string
func (t templateOption) apply(opts *options) {
opts.template = string(t)
}
// WithWriter provides a custom writer to the progress bar.
func WithWriter(w io.Writer) Option {
return writerOption{w: w}
}
type writerOption struct {
w io.Writer
}
func (w writerOption) apply(opts *options) {
opts.writer = w.w
}
// WithInterval provides an update interval for the progress bar.
func WithInterval(d time.Duration) Option {
return intervalOption(d)
}
type intervalOption time.Duration
func (i intervalOption) apply(opts *options) {
opts.updateInterval = time.Duration(i)
}
// WithStyle provides a custom styling for the progress bar.
func WithStyle(style Style) Option {
return styleOption(style)
}
type styleOption Style
func (s styleOption) apply(opts *options) {
opts.style = Style(s)
}