| 31 | 31 |
}
|
| 32 | 32 |
|
| 33 | 33 |
type bFiller struct {
|
|
34 |
rev bool
|
| 34 | 35 |
components [components]*component
|
| 35 | 36 |
tip struct {
|
| 36 | 37 |
count uint
|
| 37 | 38 |
onComplete *component
|
| 38 | 39 |
frames []*component
|
| 39 | 40 |
}
|
| 40 | |
flush func(dst io.Writer, filling, padding [][]byte)
|
| 41 | 41 |
}
|
| 42 | 42 |
|
| 43 | 43 |
type component struct {
|
|
| 112 | 112 |
}
|
| 113 | 113 |
|
| 114 | 114 |
func (s *barStyle) Build() BarFiller {
|
| 115 | |
bf := new(bFiller)
|
| 116 | |
if s.rev {
|
| 117 | |
bf.flush = func(dst io.Writer, filling, padding [][]byte) {
|
| 118 | |
flush(dst, padding, filling)
|
| 119 | |
}
|
| 120 | |
} else {
|
| 121 | |
bf.flush = flush
|
| 122 | |
}
|
|
115 |
bf := &bFiller{rev: s.rev}
|
| 123 | 116 |
bf.components[iLbound] = &component{
|
| 124 | 117 |
width: runewidth.StringWidth(stripansi.Strip(s.lbound)),
|
| 125 | 118 |
bytes: []byte(s.lbound),
|
|
| 163 | 156 |
return
|
| 164 | 157 |
}
|
| 165 | 158 |
|
| 166 | |
w.Write(s.components[iLbound].bytes)
|
| 167 | |
defer w.Write(s.components[iRbound].bytes)
|
|
159 |
ow := optimisticWriter(w)
|
|
160 |
ow(s.components[iLbound].bytes)
|
|
161 |
defer ow(s.components[iRbound].bytes)
|
| 168 | 162 |
|
| 169 | 163 |
if width == 0 {
|
| 170 | 164 |
return
|
|
| 235 | 229 |
}
|
| 236 | 230 |
}
|
| 237 | 231 |
|
| 238 | |
s.flush(w, filling, padding)
|
| 239 | |
}
|
| 240 | |
|
| 241 | |
func flush(dst io.Writer, filling, padding [][]byte) {
|
|
232 |
if s.rev {
|
|
233 |
flush(ow, padding, filling)
|
|
234 |
} else {
|
|
235 |
flush(ow, filling, padding)
|
|
236 |
}
|
|
237 |
}
|
|
238 |
|
|
239 |
func flush(ow func([]byte), filling, padding [][]byte) {
|
| 242 | 240 |
for i := len(filling) - 1; i >= 0; i-- {
|
| 243 | |
dst.Write(filling[i])
|
|
241 |
ow(filling[i])
|
| 244 | 242 |
}
|
| 245 | 243 |
for i := 0; i < len(padding); i++ {
|
| 246 | |
dst.Write(padding[i])
|
| 247 | |
}
|
| 248 | |
}
|
|
244 |
ow(padding[i])
|
|
245 |
}
|
|
246 |
}
|
|
247 |
|
|
248 |
func optimisticWriter(w io.Writer) func([]byte) {
|
|
249 |
return func(p []byte) {
|
|
250 |
_, err := w.Write(p)
|
|
251 |
if err != nil {
|
|
252 |
panic(err)
|
|
253 |
}
|
|
254 |
}
|
|
255 |
}
|