Codebase list golang-github-vbauerster-mpb / e197f40
correct merge with more than one placeholders Vladimir Bauer 6 years ago
1 changed file(s) with 18 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
11
22 import (
33 "fmt"
4 "strings"
45 "unicode/utf8"
56 )
67
6970 msg := d.Decorator.Decor(st)
7071 msgLen := utf8.RuneCountInString(msg)
7172
73 pw := msgLen / (len(d.placeHolders) + 1)
74
75 for _, ph := range d.placeHolders {
76 ph := ph
77 width := pw
78 go func() {
79 if (ph.WC.C & DextraSpace) != 0 {
80 width--
81 if width < 0 {
82 width = 0
83 }
84 }
85 ph.wch <- utf8.RuneCountInString(ph.FormatMsg(strings.Repeat(" ", width)))
86 }()
87 }
88
7289 var space int
7390 for _, ph := range d.placeHolders {
7491 space += <-ph.wch
7592 }
7693
7794 d.wc.wsync <- msgLen - space
78
7995 max := <-d.wc.wsync
8096 if (d.wc.C & DextraSpace) != 0 {
8197 max++
88104 wch chan int
89105 }
90106
91 func (d *placeHolderDecorator) Decor(st *Statistics) string {
92 go func() {
93 d.wch <- utf8.RuneCountInString(d.FormatMsg(""))
94 }()
107 func (d *placeHolderDecorator) Decor(_ *Statistics) string {
95108 return ""
96109 }