Codebase list golang-github-vbauerster-mpb / d7c471f
make staticFormat at Init Vladimir Bauer 7 years ago
2 changed file(s) with 13 addition(s) and 10 deletion(s). Raw diff Collapse all Expand all
104104 // W represents width and C represents bit set of width related config.
105105 // A decorator should embed WC, to enable width synchronization.
106106 type WC struct {
107 W int
108 C int
109 format string
110 wsync chan int
107 W int
108 C int
109 dynFormat string
110 staticFormat string
111 wsync chan int
111112 }
112113
113114 // FormatMsg formats final message according to WC.W and WC.C.
119120 if (wc.C & DextraSpace) != 0 {
120121 max++
121122 }
122 return fmt.Sprintf(fmt.Sprintf(wc.format, max), msg)
123 return fmt.Sprintf(fmt.Sprintf(wc.dynFormat, max), msg)
123124 }
124 return fmt.Sprintf(fmt.Sprintf(wc.format, wc.W), msg)
125 return fmt.Sprintf(wc.staticFormat, msg)
125126 }
126127
127128 // Init initializes width related config.
128129 func (wc *WC) Init() {
129 wc.format = "%%"
130 wc.dynFormat = "%%"
130131 if (wc.C & DidentRight) != 0 {
131 wc.format += "-"
132 wc.dynFormat += "-"
132133 }
133 wc.format += "%ds"
134 wc.dynFormat += "%ds"
135 wc.staticFormat = fmt.Sprintf(wc.dynFormat, wc.W)
134136 if (wc.C & DSyncWidth) != 0 {
135137 wc.wsync = make(chan int)
136138 }
141143 return wc.wsync, (wc.C & DSyncWidth) != 0
142144 }
143145
146 // SetConfig sets new conf and return old conf.
144147 func (wc *WC) SetConfig(conf WC) (old WC) {
145148 old = *wc
146149 *wc = conf
6363 if (d.wc.C & DextraSpace) != 0 {
6464 max++
6565 }
66 return fmt.Sprintf(fmt.Sprintf(d.wc.format, max), msg)
66 return fmt.Sprintf(fmt.Sprintf(d.wc.dynFormat, max), msg)
6767 }
6868
6969 type placeHolderDecorator struct {