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

import (
	"time"
)

// Elapsed decorator. It's wrapper of NewElapsed.
//
//	`style` one of [ET_STYLE_GO|ET_STYLE_HHMMSS|ET_STYLE_HHMM|ET_STYLE_MMSS]
//
//	`wcc` optional WC config
//
func Elapsed(style TimeStyle, wcc ...WC) Decorator {
	return NewElapsed(style, time.Now(), wcc...)
}

// NewElapsed returns elapsed time decorator.
//
//	`style` one of [ET_STYLE_GO|ET_STYLE_HHMMSS|ET_STYLE_HHMM|ET_STYLE_MMSS]
//
//	`startTime` start time
//
//	`wcc` optional WC config
//
func NewElapsed(style TimeStyle, startTime time.Time, wcc ...WC) Decorator {
	var msg string
	producer := chooseTimeProducer(style)
	fn := func(s Statistics) string {
		if !s.Completed {
			msg = producer(time.Since(startTime))
		}
		return msg
	}
	return Any(fn, wcc...)
}