| 30 | 30 |
md := &mergeDecorator{
|
| 31 | 31 |
Decorator: decorator,
|
| 32 | 32 |
wc: decorator.GetConf(),
|
| 33 | |
placeHolders: make([]*placeHolderDecorator, len(placeholders)),
|
|
33 |
placeHolders: make([]Decorator, len(placeholders)),
|
| 34 | 34 |
}
|
| 35 | 35 |
decorator.SetConf(WC{})
|
| 36 | 36 |
for i, wc := range placeholders {
|
|
| 45 | 45 |
type mergeDecorator struct {
|
| 46 | 46 |
Decorator
|
| 47 | 47 |
wc WC
|
| 48 | |
placeHolders []*placeHolderDecorator
|
|
48 |
placeHolders []Decorator
|
| 49 | 49 |
}
|
| 50 | 50 |
|
| 51 | 51 |
func (d *mergeDecorator) GetConf() WC {
|
|
| 56 | 56 |
d.wc = conf.Init()
|
| 57 | 57 |
}
|
| 58 | 58 |
|
| 59 | |
func (d *mergeDecorator) MergeUnwrap() []Decorator {
|
| 60 | |
decorators := make([]Decorator, len(d.placeHolders))
|
| 61 | |
for i, ph := range d.placeHolders {
|
| 62 | |
decorators[i] = ph
|
| 63 | |
}
|
| 64 | |
return decorators
|
|
59 |
func (d *mergeDecorator) PlaceHolders() []Decorator {
|
|
60 |
return d.placeHolders
|
| 65 | 61 |
}
|
| 66 | 62 |
|
| 67 | 63 |
func (d *mergeDecorator) Sync() (chan int, bool) {
|
|
| 81 | 77 |
cellCount++
|
| 82 | 78 |
}
|
| 83 | 79 |
|
| 84 | |
total := runewidth.StringWidth(d.placeHolders[0].FormatMsg(""))
|
|
80 |
total := runewidth.StringWidth(d.placeHolders[0].GetConf().FormatMsg(""))
|
| 85 | 81 |
pw := (cellCount - total) / len(d.placeHolders)
|
| 86 | 82 |
rem := (cellCount - total) % len(d.placeHolders)
|
| 87 | 83 |
|
| 88 | 84 |
var diff int
|
| 89 | 85 |
for i := 1; i < len(d.placeHolders); i++ {
|
| 90 | |
ph := d.placeHolders[i]
|
|
86 |
wc := d.placeHolders[i].GetConf()
|
| 91 | 87 |
width := pw - diff
|
| 92 | |
if (ph.WC.C & DextraSpace) != 0 {
|
|
88 |
if (wc.C & DextraSpace) != 0 {
|
| 93 | 89 |
width--
|
| 94 | 90 |
if width < 0 {
|
| 95 | 91 |
width = 0
|
| 96 | 92 |
}
|
| 97 | 93 |
}
|
| 98 | |
max := runewidth.StringWidth(ph.FormatMsg(strings.Repeat(" ", width)))
|
|
94 |
max := runewidth.StringWidth(wc.FormatMsg(strings.Repeat(" ", width)))
|
| 99 | 95 |
total += max
|
| 100 | 96 |
diff = max - pw
|
| 101 | 97 |
}
|