diff --git a/decor/decorator.go b/decor/decorator.go index b699d48..877de53 100644 --- a/decor/decorator.go +++ b/decor/decorator.go @@ -144,11 +144,11 @@ return wc.wsync, (wc.C & DSyncWidth) != 0 } -// SetConfig sets new conf and return old conf. +// SetConfig sets new conf and returns old one. func (wc *WC) SetConfig(conf WC) (old WC) { + conf.Init() old = *wc *wc = conf - wc.Init() return old } diff --git a/decor/merge.go b/decor/merge.go index b0c4a4f..44001c8 100644 --- a/decor/merge.go +++ b/decor/merge.go @@ -2,7 +2,6 @@ import ( "fmt" - "strings" "unicode/utf8" ) @@ -55,20 +54,23 @@ func (d *mergeDecorator) Decor(st *Statistics) string { msg := d.Decorator.Decor(st) msgLen := utf8.RuneCountInString(msg) - pWidth := msgLen / (len(d.placeHolders) + 1) - mod := msgLen % (len(d.placeHolders) + 1) - d.wc.wsync <- pWidth + mod + + var pWidth int for _, ph := range d.placeHolders { - ph.wsync <- pWidth + pWidth += <-ph.wsync } + + if msgLen > pWidth { + d.wc.wsync <- msgLen - pWidth + } else { + d.wc.wsync <- msgLen + } + max := <-d.wc.wsync - for _, ph := range d.placeHolders { - max += <-ph.wsync - } if (d.wc.C & DextraSpace) != 0 { max++ } - return fmt.Sprintf(fmt.Sprintf(d.wc.dynFormat, max), msg) + return fmt.Sprintf(fmt.Sprintf(d.wc.dynFormat, max+pWidth), msg) } type placeHolderDecorator struct { @@ -78,9 +80,7 @@ func (d *placeHolderDecorator) Decor(st *Statistics) string { go func() { - width := <-d.wsync - msg := strings.Repeat(" ", width) - d.wsync <- utf8.RuneCountInString(d.FormatMsg(msg)) + d.wsync <- utf8.RuneCountInString(d.FormatMsg("")) }() return "" }