minor: viewWidth to width
Vladimir Bauer
2 years ago
| 84 | 84 | // in order to format string according to decor.WC settings. |
| 85 | 85 | // No need to implement manually as long as decor.WC is embedded. |
| 86 | 86 | type Formatter interface { |
| 87 | Format(string) (str string, viewWidth int) | |
| 87 | Format(string) (_ string, width int) | |
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | // Wrapper interface. |
| 137 | 137 | // Format should be called by any Decorator implementation. |
| 138 | 138 | // Returns formatted string and its view (visual) width. |
| 139 | 139 | 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 | |
| 143 | 143 | } else if (wc.C & DextraSpace) != 0 { |
| 144 | viewWidth++ | |
| 144 | width++ | |
| 145 | 145 | } |
| 146 | 146 | if (wc.C & DSyncWidth) != 0 { |
| 147 | wc.wsync <- viewWidth | |
| 148 | viewWidth = <-wc.wsync | |
| 147 | wc.wsync <- width | |
| 148 | width = <-wc.wsync | |
| 149 | 149 | } |
| 150 | return wc.fill(str, viewWidth), viewWidth | |
| 150 | return wc.fill(str, width), width | |
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | // Init initializes width related config. |