Codebase list golang-github-vbauerster-mpb / f6ccfdd
minor: viewWidth to width Vladimir Bauer 2 years ago
1 changed file(s) with 8 addition(s) and 8 deletion(s). Raw diff Collapse all Expand all
8484 // in order to format string according to decor.WC settings.
8585 // No need to implement manually as long as decor.WC is embedded.
8686 type Formatter interface {
87 Format(string) (str string, viewWidth int)
87 Format(string) (_ string, width int)
8888 }
8989
9090 // Wrapper interface.
137137 // Format should be called by any Decorator implementation.
138138 // Returns formatted string and its view (visual) width.
139139 func (wc WC) Format(str string) (string, int) {
140 viewWidth := runewidth.StringWidth(str)
141 if wc.W > viewWidth {
142 viewWidth = wc.W
140 width := runewidth.StringWidth(str)
141 if wc.W > width {
142 width = wc.W
143143 } else if (wc.C & DextraSpace) != 0 {
144 viewWidth++
144 width++
145145 }
146146 if (wc.C & DSyncWidth) != 0 {
147 wc.wsync <- viewWidth
148 viewWidth = <-wc.wsync
147 wc.wsync <- width
148 width = <-wc.wsync
149149 }
150 return wc.fill(str, viewWidth), viewWidth
150 return wc.fill(str, width), width
151151 }
152152
153153 // Init initializes width related config.