merge decorator fix
Vladimir Bauer
7 years ago
| 1 | 1 |
|
| 2 | 2 |
import (
|
| 3 | 3 |
"fmt"
|
| 4 | |
"strings"
|
| 5 | 4 |
"unicode/utf8"
|
| 6 | 5 |
)
|
| 7 | 6 |
|
|
| 54 | 53 |
func (d *mergeDecorator) Decor(st *Statistics) string {
|
| 55 | 54 |
msg := d.Decorator.Decor(st)
|
| 56 | 55 |
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
|
| 60 | 58 |
for _, ph := range d.placeHolders {
|
| 61 | |
ph.wsync <- pWidth
|
|
59 |
pWidth += <-ph.wsync
|
| 62 | 60 |
}
|
|
61 |
|
|
62 |
if msgLen > pWidth {
|
|
63 |
d.wc.wsync <- msgLen - pWidth
|
|
64 |
} else {
|
|
65 |
d.wc.wsync <- msgLen
|
|
66 |
}
|
|
67 |
|
| 63 | 68 |
max := <-d.wc.wsync
|
| 64 | |
for _, ph := range d.placeHolders {
|
| 65 | |
max += <-ph.wsync
|
| 66 | |
}
|
| 67 | 69 |
if (d.wc.C & DextraSpace) != 0 {
|
| 68 | 70 |
max++
|
| 69 | 71 |
}
|
| 70 | |
return fmt.Sprintf(fmt.Sprintf(d.wc.dynFormat, max), msg)
|
|
72 |
return fmt.Sprintf(fmt.Sprintf(d.wc.dynFormat, max+pWidth), msg)
|
| 71 | 73 |
}
|
| 72 | 74 |
|
| 73 | 75 |
type placeHolderDecorator struct {
|
|
| 77 | 79 |
|
| 78 | 80 |
func (d *placeHolderDecorator) Decor(st *Statistics) string {
|
| 79 | 81 |
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(""))
|
| 83 | 83 |
}()
|
| 84 | 84 |
return ""
|
| 85 | 85 |
}
|