meaningful vars
Vladimir Bauer
6 years ago
| 127 | 127 | // FormatMsg formats final message according to WC.W and WC.C. |
| 128 | 128 | // Should be called by any Decorator implementation. |
| 129 | 129 | func (wc *WC) FormatMsg(msg string) string { |
| 130 | max := utf8.RuneCountInString(stripansi.Strip(msg)) | |
| 130 | var format string | |
| 131 | runeCount := utf8.RuneCountInString(stripansi.Strip(msg)) | |
| 132 | ansiCount := utf8.RuneCountInString(msg) - runeCount | |
| 131 | 133 | if (wc.C & DSyncWidth) != 0 { |
| 132 | wc.wsync <- max | |
| 133 | max = (utf8.RuneCountInString(msg) - max) + <-wc.wsync | |
| 134 | wc.wsync <- runeCount | |
| 135 | max := <-wc.wsync | |
| 134 | 136 | if (wc.C & DextraSpace) != 0 { |
| 135 | 137 | max++ |
| 136 | 138 | } |
| 139 | format = fmt.Sprintf(wc.dynFormat, ansiCount+max) | |
| 137 | 140 | } else { |
| 138 | max = (utf8.RuneCountInString(msg) - max) + wc.W | |
| 141 | format = fmt.Sprintf(wc.dynFormat, ansiCount+wc.W) | |
| 139 | 142 | } |
| 140 | return fmt.Sprintf(fmt.Sprintf(wc.dynFormat, max), msg) | |
| 143 | return fmt.Sprintf(format, msg) | |
| 141 | 144 | } |
| 142 | 145 | |
| 143 | 146 | // Init initializes width related config. |