Codebase list golang-github-vbauerster-mpb / f1728eb
merge decorator fix Vladimir Bauer 7 years ago
2 changed file(s) with 14 addition(s) and 14 deletion(s). Raw diff Collapse all Expand all
143143 return wc.wsync, (wc.C & DSyncWidth) != 0
144144 }
145145
146 // SetConfig sets new conf and return old conf.
146 // SetConfig sets new conf and returns old one.
147147 func (wc *WC) SetConfig(conf WC) (old WC) {
148 conf.Init()
148149 old = *wc
149150 *wc = conf
150 wc.Init()
151151 return old
152152 }
153153
11
22 import (
33 "fmt"
4 "strings"
54 "unicode/utf8"
65 )
76
5453 func (d *mergeDecorator) Decor(st *Statistics) string {
5554 msg := d.Decorator.Decor(st)
5655 msgLen := utf8.RuneCountInString(msg)
57 pWidth := msgLen / (len(d.placeHolders) + 1)
58 mod := msgLen % (len(d.placeHolders) + 1)
59 d.wc.wsync <- pWidth + mod
56
57 var pWidth int
6058 for _, ph := range d.placeHolders {
61 ph.wsync <- pWidth
59 pWidth += <-ph.wsync
6260 }
61
62 if msgLen > pWidth {
63 d.wc.wsync <- msgLen - pWidth
64 } else {
65 d.wc.wsync <- msgLen
66 }
67
6368 max := <-d.wc.wsync
64 for _, ph := range d.placeHolders {
65 max += <-ph.wsync
66 }
6769 if (d.wc.C & DextraSpace) != 0 {
6870 max++
6971 }
70 return fmt.Sprintf(fmt.Sprintf(d.wc.dynFormat, max), msg)
72 return fmt.Sprintf(fmt.Sprintf(d.wc.dynFormat, max+pWidth), msg)
7173 }
7274
7375 type placeHolderDecorator struct {
7779
7880 func (d *placeHolderDecorator) Decor(st *Statistics) string {
7981 go func() {
80 width := <-d.wsync
81 msg := strings.Repeat(" ", width)
82 d.wsync <- utf8.RuneCountInString(d.FormatMsg(msg))
82 d.wsync <- utf8.RuneCountInString(d.FormatMsg(""))
8383 }()
8484 return ""
8585 }