-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscrollingspinner.go
80 lines (64 loc) · 1.87 KB
/
scrollingspinner.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
package specs
type ScrollingSpinnerInterface interface {
ProgressInterface
}
type ScrollingSpinnerDefinition[T any] struct {
ProgressDefinition[T]
done string
phases Phases
pending string
}
var (
_ ScrollingSpinnerSpecification[ProgressInterface] = (*ScrollingSpinnerDefinition[ProgressInterface])(nil)
_ ScrollingSpinnerConfiguration = (*ScrollingSpinnerDefinition[ProgressInterface])(nil)
)
// NewScrollingSpinnerDef can be used to create a nested definition
// for a derived scrolling spinner definition.
func NewScrollingSpinnerDefinition[T any](self Self[T], text string, length int) ScrollingSpinnerDefinition[T] {
d := ScrollingSpinnerDefinition[T]{
ProgressDefinition: NewProgressDefinition(self),
done: Done,
}
t := text + " "
if len(t) <= length {
t = t + " " + text
}
var phases []string
s := t + t
for i := 0; i < len(t); i++ {
phases = append(phases, s[i:i+length])
}
d.phases = NewStaticPhases(phases...)
return d
}
func (d *ScrollingSpinnerDefinition[T]) Dup(s Self[T]) ScrollingSpinnerDefinition[T] {
dup := *d
dup.ProgressDefinition = d.ProgressDefinition.Dup(s)
return dup
}
func (d *ScrollingSpinnerDefinition[T]) SetDone(m string) T {
d.done = m
return d.Self()
}
func (d *ScrollingSpinnerDefinition[T]) GetDone() string {
return d.done
}
func (d *ScrollingSpinnerDefinition[T]) SetPending(m string) T {
d.pending = m
return d.Self()
}
func (d *ScrollingSpinnerDefinition[T]) GetPending() string {
return d.pending
}
func (d *ScrollingSpinnerDefinition[T]) GetSpeed() int {
return 3
}
func (d *ScrollingSpinnerDefinition[T]) GetPhases() Phases {
return d.phases
}
////////////////////////////////////////////////////////////////////////////////
type ScrollingSpinnerSpecification[T any] interface {
ProgressSpecification[T]
SetDone(string) T
}
type ScrollingSpinnerConfiguration = SpinnerConfiguration