Codebase list golang-github-vbauerster-mpb / 47230ce
counters producer Vladimir Bauer 6 years ago
1 changed file(s) with 20 addition(s) and 15 deletion(s). Raw diff Collapse all Expand all
4646 for _, widthConf := range wcc {
4747 wc = widthConf
4848 }
49 if pairFmt == "" {
50 pairFmt = "%d / %d"
51 }
5249 d := &countersDecorator{
53 WC: wc.Init(),
54 unit: unit,
55 pairFmt: pairFmt,
50 WC: wc.Init(),
51 producer: chooseSizeProducer(unit, pairFmt),
5652 }
5753 return d
5854 }
5955
6056 type countersDecorator struct {
6157 WC
62 unit int
63 pairFmt string
58 producer func(*Statistics) string
6459 }
6560
6661 func (d *countersDecorator) Decor(st *Statistics) string {
67 var res string
68 switch d.unit {
62 return d.producer(st)
63 }
64
65 func chooseSizeProducer(unit int, format string) func(*Statistics) string {
66 if format == "" {
67 format = "%d / %d"
68 }
69 switch unit {
6970 case UnitKiB:
70 res = fmt.Sprintf(d.pairFmt, SizeB1024(st.Current), SizeB1024(st.Total))
71 return func(st *Statistics) string {
72 return fmt.Sprintf(format, SizeB1024(st.Current), SizeB1024(st.Total))
73 }
7174 case UnitKB:
72 res = fmt.Sprintf(d.pairFmt, SizeB1000(st.Current), SizeB1000(st.Total))
75 return func(st *Statistics) string {
76 return fmt.Sprintf(format, SizeB1000(st.Current), SizeB1000(st.Total))
77 }
7378 default:
74 res = fmt.Sprintf(d.pairFmt, st.Current, st.Total)
79 return func(st *Statistics) string {
80 return fmt.Sprintf(format, st.Current, st.Total)
81 }
7582 }
76
77 return d.FormatMsg(res)
7883 }