-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgroup.go
54 lines (42 loc) · 1.35 KB
/
group.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
package ttyprogress
import (
"github.com/mandelsoft/ttyprogress/ppi"
"github.com/mandelsoft/ttyprogress/specs"
)
type Group interface {
Container
Gap() string
ppi.ProgressInterface
}
type GroupDefinition[E specs.ProgressInterface] struct {
specs.GroupDefinition[*GroupDefinition[E], E]
}
func NewGroup[E specs.ProgressInterface](p specs.GroupProgressElementDefinition[E]) *GroupDefinition[E] {
d := &GroupDefinition[E]{}
d.GroupDefinition = *specs.NewGroupDefinition[*GroupDefinition[E], E](specs.NewSelf(d), p)
return d
}
func (d *GroupDefinition[E]) Dup() *GroupDefinition[E] {
dup := &GroupDefinition[E]{}
dup.GroupDefinition = d.GroupDefinition.Dup(specs.NewSelf(d))
return dup
}
func (d *GroupDefinition[E]) Add(c Container) (Group, error) {
return newGroup[E](c, d)
}
////////////////////////////////////////////////////////////////////////////////
type _group[E specs.ProgressInterface] struct {
*ppi.GroupBase[E]
}
var _ Group = (*_group[specs.ProgressInterface])(nil)
func newGroup[E ppi.ProgressInterface](p Container, c specs.GroupConfiguration[E]) (Group, error) {
g := &_group[E]{}
g.GroupBase, _ = ppi.NewGroupBase[E](p, c, func(b *ppi.GroupBase[E]) (E, specs.GroupNotifier, error) {
e, err := c.GetProgress().Add(b)
if err != nil {
return e, nil, err
}
return e, c.GetProgress().GetGroupNotifier(), err
})
return g, nil
}