summaryrefslogtreecommitdiffstats
path: root/dependencies/pkg/mod/github.com/vbauerster/mpb/v6@v6.0.4/decor/on_complete.go
blob: f46b19abaa953ac8259369935d449e6a385953ca (plain)
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
package decor

// OnComplete returns decorator, which wraps provided decorator, with
// sole purpose to display provided message on complete event.
//
//	`decorator` Decorator to wrap
//
//	`message` message to display on complete event
//
func OnComplete(decorator Decorator, message string) Decorator {
	d := &onCompleteWrapper{
		Decorator: decorator,
		msg:       message,
	}
	if md, ok := decorator.(*mergeDecorator); ok {
		d.Decorator, md.Decorator = md.Decorator, d
		return md
	}
	return d
}

type onCompleteWrapper struct {
	Decorator
	msg string
}

func (d *onCompleteWrapper) Decor(s Statistics) string {
	if s.Completed {
		wc := d.GetConf()
		return wc.FormatMsg(d.msg)
	}
	return d.Decorator.Decor(s)
}

func (d *onCompleteWrapper) Base() Decorator {
	return d.Decorator
}