Codebase list golang-github-vbauerster-mpb / d92e788
New feature: BarStyle Inclusive Vladimir Bauer 4 years ago
2 changed file(s) with 508 addition(s) and 94 deletion(s). Raw diff Collapse all Expand all
2626 Refiller(string) BarStyleComposer
2727 Padding(string) BarStyleComposer
2828 Tip(...string) BarStyleComposer
29 Inclusive(tipOnCompleteIndex uint) BarStyleComposer
2930 Reverse() BarStyleComposer
3031 }
3132
3233 type bFiller struct {
3334 components [components]*component
3435 tip struct {
35 count uint
36 frames []*component
36 count uint
37 onCompleteIndex uint
38 inclusive bool
39 frames []*component
3740 }
3841 flush func(dst io.Writer, filling, padding [][]byte)
3942 }
4447 }
4548
4649 type barStyle struct {
47 lbound string
48 rbound string
49 filler string
50 refiller string
51 padding string
52 tip []string
53 rev bool
50 lbound string
51 rbound string
52 filler string
53 refiller string
54 padding string
55 tip []string
56 tipOnCompleteIndex uint
57 tipInclusive bool
58 rev bool
5459 }
5560
5661 // BarStyle constructs default bar style which can be altered via
98103 return s
99104 }
100105
106 func (s *barStyle) Inclusive(tipOnCompleteIndex uint) BarStyleComposer {
107 s.tipInclusive = true
108 s.tipOnCompleteIndex = tipOnCompleteIndex
109 return s
110 }
111
101112 func (s *barStyle) Reverse() BarStyleComposer {
102113 s.rev = true
103114 return s
132143 width: runewidth.StringWidth(stripansi.Strip(s.padding)),
133144 bytes: []byte(s.padding),
134145 }
146 bf.tip.inclusive = s.tipInclusive
147 bf.tip.onCompleteIndex = s.tipOnCompleteIndex
135148 bf.tip.frames = make([]*component, len(s.tip))
136149 for i, t := range s.tip {
137150 bf.tip.frames[i] = &component{
154167 w.Write(s.components[iLbound].bytes)
155168 defer w.Write(s.components[iRbound].bytes)
156169
170 var filling [][]byte
171 var padding [][]byte
172 var tip *component
173 var refWidth int
157174 curWidth := int(internal.PercentageRound(stat.Total, stat.Current, width))
158 refWidth, filled := 0, curWidth
159 filling := make([][]byte, 0, curWidth)
160
161 if curWidth > 0 && curWidth != width {
162 tipFrame := s.tip.frames[s.tip.count%uint(len(s.tip.frames))]
163 filling = append(filling, tipFrame.bytes)
164 curWidth -= tipFrame.width
175 filled := curWidth
176
177 if stat.Current == stat.Total {
178 if s.tip.onCompleteIndex >= uint(len(s.tip.frames)) {
179 s.tip.onCompleteIndex = 0
180 }
181 tip = s.tip.frames[s.tip.onCompleteIndex]
182 } else {
183 tip = s.tip.frames[s.tip.count%uint(len(s.tip.frames))]
184 }
185
186 if s.tip.inclusive {
187 if curWidth > 0 {
188 filling = append(filling, tip.bytes)
189 curWidth -= tip.width
190 s.tip.count++
191 }
192 } else if curWidth < width {
193 filling = append(filling, tip.bytes)
194 filled += tip.width
165195 s.tip.count++
166196 }
167197
191221
192222 filled -= curWidth + refWidth
193223 padWidth := width - filled
194 padding := make([][]byte, 0, padWidth)
195224 for padWidth > 0 && padWidth >= s.components[iPadding].width {
196225 padding = append(padding, s.components[iPadding].bytes)
197226 padWidth -= s.components[iPadding].width
7474 total: 60,
7575 current: 20,
7676 trim: true,
77 want: "[-]",
77 want: "[>]",
7878 },
7979 },
8080 4: {
8989 total: 60,
9090 current: 20,
9191 trim: true,
92 want: "[>-]",
92 want: "[=>]",
9393 },
9494 },
9595 5: {
9797 name: "t,c{60,20}",
9898 total: 60,
9999 current: 20,
100 want: " [-] ",
101 },
102 {
103 name: "t,c{60,20}trim",
104 total: 60,
105 current: 20,
106 trim: true,
107 want: "[>--]",
100 want: " [>] ",
101 },
102 {
103 name: "t,c{60,20}trim",
104 total: 60,
105 current: 20,
106 trim: true,
107 want: "[=>-]",
108108 },
109109 },
110110 6: {
112112 name: "t,c{60,20}",
113113 total: 60,
114114 current: 20,
115 want: " [>-] ",
116 },
117 {
118 name: "t,c{60,20}trim",
119 total: 60,
120 current: 20,
121 trim: true,
122 want: "[>---]",
115 want: " [=>] ",
116 },
117 {
118 name: "t,c{60,20}trim",
119 total: 60,
120 current: 20,
121 trim: true,
122 want: "[=>--]",
123123 },
124124 },
125125 7: {
127127 name: "t,c{60,20}",
128128 total: 60,
129129 current: 20,
130 want: " [>--] ",
131 },
132 {
133 name: "t,c{60,20}trim",
134 total: 60,
135 current: 20,
136 trim: true,
137 want: "[=>---]",
130 want: " [=>-] ",
131 },
132 {
133 name: "t,c{60,20}trim",
134 total: 60,
135 current: 20,
136 trim: true,
137 want: "[==>--]",
138138 },
139139 },
140140 8: {
142142 name: "t,c{60,20}",
143143 total: 60,
144144 current: 20,
145 want: " [>---] ",
146 },
147 {
148 name: "t,c{60,20}trim",
149 total: 60,
150 current: 20,
151 trim: true,
152 want: "[=>----]",
145 want: " [=>--] ",
146 },
147 {
148 name: "t,c{60,20}trim",
149 total: 60,
150 current: 20,
151 trim: true,
152 want: "[==>---]",
153153 },
154154 },
155155 80: {
157157 name: "t,c{60,20}",
158158 total: 60,
159159 current: 20,
160 want: " [========================>---------------------------------------------------] ",
161 },
162 {
163 name: "t,c{60,20}trim",
164 total: 60,
165 current: 20,
166 trim: true,
167 want: "[=========================>----------------------------------------------------]",
160 want: " [=========================>--------------------------------------------------] ",
161 },
162 {
163 name: "t,c{60,20}trim",
164 total: 60,
165 current: 20,
166 trim: true,
167 want: "[==========================>---------------------------------------------------]",
168168 },
169169 {
170170 name: "t,c,bw{60,20,60}",
171171 total: 60,
172172 current: 20,
173173 barWidth: 60,
174 want: " [==================>---------------------------------------] ",
174 want: " [===================>--------------------------------------] ",
175175 },
176176 {
177177 name: "t,c,bw{60,20,60}trim",
179179 current: 20,
180180 barWidth: 60,
181181 trim: true,
182 want: "[==================>---------------------------------------]",
182 want: "[===================>--------------------------------------]",
183183 },
184184 },
185185 99: {
195195 name: "[のだつ] t,c{99,2}",
196196 total: 99,
197197 current: 2,
198 want: " [だつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつ…] ",
198 want: " [のだつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつ…] ",
199199 },
200200 {
201201 style: BarStyle().Lbound("[").Filler("の").Tip("だ").Padding("つ").Rbound("]"),
202202 name: "[のだつ] t,c{99,3}",
203203 total: 99,
204204 current: 3,
205 want: " [だつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつ…] ",
205 want: " [のだつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつ…] ",
206206 },
207207 {
208208 style: BarStyle().Lbound("[").Filler("の").Tip("だ").Padding("つ").Rbound("]"),
209209 name: "[のだつ] t,c{99,4}",
210210 total: 99,
211211 current: 4,
212 want: " [のだつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつ…] ",
212 want: " [ののだつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつ…] ",
213213 },
214214 {
215215 style: BarStyle().Lbound("[").Filler("の").Tip("だ").Padding("つ").Rbound("]"),
216216 name: "[のだつ] t,c{99,5}",
217217 total: 99,
218218 current: 5,
219 want: " [のだつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつ…] ",
219 want: " [ののだつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつ…] ",
220220 },
221221 {
222222 style: BarStyle().Lbound("[").Filler("の").Tip("だ").Padding("つ").Rbound("]"),
223223 name: "[のだつ] t,c{99,6}",
224224 total: 99,
225225 current: 6,
226 want: " [ののだつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつ…] ",
226 want: " [のののだつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつ…] ",
227227 },
228228 {
229229 style: BarStyle().Lbound("[").Filler("の").Tip("だ").Padding("つ").Rbound("]").Reverse(),
230230 name: "[のだつ] t,c{99,6}rev",
231231 total: 99,
232232 current: 6,
233 want: " […つつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつだのの] ",
233 want: " […つつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつだののの] ",
234234 },
235235 },
236236 100: {
238238 name: "t,c{100,0}",
239239 total: 100,
240240 current: 0,
241 want: " [------------------------------------------------------------------------------------------------] ",
241 want: " [>-----------------------------------------------------------------------------------------------] ",
242242 },
243243 {
244244 name: "t,c{100,0}trim",
245245 total: 100,
246246 current: 0,
247247 trim: true,
248 want: "[--------------------------------------------------------------------------------------------------]",
248 want: "[>-------------------------------------------------------------------------------------------------]",
249249 },
250250 {
251251 name: "t,c{100,1}",
252252 total: 100,
253253 current: 1,
254 want: " [>-----------------------------------------------------------------------------------------------] ",
254 want: " [=>----------------------------------------------------------------------------------------------] ",
255255 },
256256 {
257257 name: "t,c{100,1}trim",
258258 total: 100,
259259 current: 1,
260260 trim: true,
261 want: "[>-------------------------------------------------------------------------------------------------]",
261 want: "[=>------------------------------------------------------------------------------------------------]",
262262 },
263263 {
264264 name: "t,c{100,99}",
265265 total: 100,
266266 current: 99,
267 want: " [==============================================================================================>-] ",
267 want: " [===============================================================================================>] ",
268268 },
269269 {
270270 name: "t,c{100,99}trim",
271271 total: 100,
272272 current: 99,
273273 trim: true,
274 want: "[================================================================================================>-]",
274 want: "[=================================================================================================>]",
275275 },
276276 {
277277 name: "t,c{100,100}",
298298 name: "t,c{100,33}",
299299 total: 100,
300300 current: 33,
301 want: " [===============================>----------------------------------------------------------------] ",
301 want: " [================================>---------------------------------------------------------------] ",
302302 },
303303 {
304304 name: "t,c{100,33}trim",
305305 total: 100,
306306 current: 33,
307307 trim: true,
308 want: "[===============================>------------------------------------------------------------------]",
308 want: "[================================>-----------------------------------------------------------------]",
309309 },
310310 {
311311 style: BarStyle().Tip("<").Reverse(),
313313 total: 100,
314314 current: 33,
315315 trim: true,
316 want: "[------------------------------------------------------------------<===============================]",
316 want: "[-----------------------------------------------------------------<================================]",
317317 },
318318 {
319319 name: "t,c,r{100,33,33}",
320320 total: 100,
321321 current: 33,
322322 refill: 33,
323 want: " [+++++++++++++++++++++++++++++++>----------------------------------------------------------------] ",
323 want: " [++++++++++++++++++++++++++++++++>---------------------------------------------------------------] ",
324324 },
325325 {
326326 name: "t,c,r{100,33,33}trim",
328328 current: 33,
329329 refill: 33,
330330 trim: true,
331 want: "[+++++++++++++++++++++++++++++++>------------------------------------------------------------------]",
331 want: "[++++++++++++++++++++++++++++++++>-----------------------------------------------------------------]",
332332 },
333333 {
334334 style: BarStyle().Tip("<").Reverse(),
337337 current: 33,
338338 refill: 33,
339339 trim: true,
340 want: "[------------------------------------------------------------------<+++++++++++++++++++++++++++++++]",
340 want: "[-----------------------------------------------------------------<++++++++++++++++++++++++++++++++]",
341341 },
342342 {
343343 name: "t,c,r{100,40,33}",
344344 total: 100,
345345 current: 40,
346346 refill: 33,
347 want: " [++++++++++++++++++++++++++++++++=====>----------------------------------------------------------] ",
347 want: " [++++++++++++++++++++++++++++++++======>---------------------------------------------------------] ",
348348 },
349349 {
350350 name: "t,c,r{100,40,33}trim",
352352 current: 40,
353353 refill: 33,
354354 trim: true,
355 want: "[++++++++++++++++++++++++++++++++======>-----------------------------------------------------------]",
355 want: "[++++++++++++++++++++++++++++++++=======>----------------------------------------------------------]",
356356 },
357357 {
358358 style: BarStyle().Tip("<").Reverse(),
360360 total: 100,
361361 current: 40,
362362 refill: 33,
363 want: " [----------------------------------------------------------<=====++++++++++++++++++++++++++++++++] ",
363 want: " [---------------------------------------------------------<======++++++++++++++++++++++++++++++++] ",
364364 },
365365 {
366366 style: BarStyle().Tip("<").Reverse(),
369369 current: 40,
370370 refill: 33,
371371 trim: true,
372 want: "[-----------------------------------------------------------<======++++++++++++++++++++++++++++++++]",
373 },
374 },
375 197: {
376 {
377 name: "t,c,r{97486999,2805950,2805483}trim",
378 total: 97486999,
379 current: 2805950,
380 refill: 2805483,
381 barWidth: 60,
382 trim: true,
383 want: "[+>--------------------------------------------------------]",
372 want: "[----------------------------------------------------------<=======++++++++++++++++++++++++++++++++]",
384373 },
385374 },
386375 }
412401 }
413402 }
414403
404 func TestDrawTipInclusive(t *testing.T) {
405 // key is termWidth
406 testSuite := map[int][]struct {
407 style BarStyleComposer
408 name string
409 total int64
410 current int64
411 refill int64
412 barWidth int
413 trim bool
414 want string
415 }{
416 0: {
417 {
418 name: "t,c{60,20}",
419 total: 60,
420 current: 20,
421 want: "",
422 },
423 {
424 name: "t,c{60,20}trim",
425 total: 60,
426 current: 20,
427 trim: true,
428 want: "",
429 },
430 },
431 1: {
432 {
433 name: "t,c{60,20}",
434 total: 60,
435 current: 20,
436 want: "",
437 },
438 {
439 name: "t,c{60,20}trim",
440 total: 60,
441 current: 20,
442 trim: true,
443 want: "",
444 },
445 },
446 2: {
447 {
448 name: "t,c{60,20}",
449 total: 60,
450 current: 20,
451 want: " ",
452 },
453 {
454 name: "t,c{60,20}trim",
455 total: 60,
456 current: 20,
457 trim: true,
458 want: "[]",
459 },
460 },
461 3: {
462 {
463 name: "t,c{60,20}",
464 total: 60,
465 current: 20,
466 want: " ",
467 },
468 {
469 name: "t,c{60,20}trim",
470 total: 60,
471 current: 20,
472 trim: true,
473 want: "[-]",
474 },
475 },
476 4: {
477 {
478 name: "t,c{60,20}",
479 total: 60,
480 current: 20,
481 want: " [] ",
482 },
483 {
484 name: "t,c{60,20}trim",
485 total: 60,
486 current: 20,
487 trim: true,
488 want: "[>-]",
489 },
490 },
491 5: {
492 {
493 name: "t,c{60,20}",
494 total: 60,
495 current: 20,
496 want: " [-] ",
497 },
498 {
499 name: "t,c{60,20}trim",
500 total: 60,
501 current: 20,
502 trim: true,
503 want: "[>--]",
504 },
505 },
506 6: {
507 {
508 name: "t,c{60,20}",
509 total: 60,
510 current: 20,
511 want: " [>-] ",
512 },
513 {
514 name: "t,c{60,20}trim",
515 total: 60,
516 current: 20,
517 trim: true,
518 want: "[>---]",
519 },
520 },
521 7: {
522 {
523 name: "t,c{60,20}",
524 total: 60,
525 current: 20,
526 want: " [>--] ",
527 },
528 {
529 name: "t,c{60,20}trim",
530 total: 60,
531 current: 20,
532 trim: true,
533 want: "[=>---]",
534 },
535 },
536 8: {
537 {
538 name: "t,c{60,20}",
539 total: 60,
540 current: 20,
541 want: " [>---] ",
542 },
543 {
544 name: "t,c{60,20}trim",
545 total: 60,
546 current: 20,
547 trim: true,
548 want: "[=>----]",
549 },
550 },
551 80: {
552 {
553 name: "t,c{60,20}",
554 total: 60,
555 current: 20,
556 want: " [========================>---------------------------------------------------] ",
557 },
558 {
559 name: "t,c{60,20}trim",
560 total: 60,
561 current: 20,
562 trim: true,
563 want: "[=========================>----------------------------------------------------]",
564 },
565 {
566 name: "t,c,bw{60,20,60}",
567 total: 60,
568 current: 20,
569 barWidth: 60,
570 want: " [==================>---------------------------------------] ",
571 },
572 {
573 name: "t,c,bw{60,20,60}trim",
574 total: 60,
575 current: 20,
576 barWidth: 60,
577 trim: true,
578 want: "[==================>---------------------------------------]",
579 },
580 },
581 99: {
582 {
583 style: BarStyle().Lbound("[").Filler("の").Tip("だ").Padding("つ").Rbound("]"),
584 name: "[のだつ] t,c{99,1}",
585 total: 99,
586 current: 1,
587 want: " [だつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつ…] ",
588 },
589 {
590 style: BarStyle().Lbound("[").Filler("の").Tip("だ").Padding("つ").Rbound("]"),
591 name: "[のだつ] t,c{99,2}",
592 total: 99,
593 current: 2,
594 want: " [だつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつ…] ",
595 },
596 {
597 style: BarStyle().Lbound("[").Filler("の").Tip("だ").Padding("つ").Rbound("]"),
598 name: "[のだつ] t,c{99,3}",
599 total: 99,
600 current: 3,
601 want: " [だつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつ…] ",
602 },
603 {
604 style: BarStyle().Lbound("[").Filler("の").Tip("だ").Padding("つ").Rbound("]"),
605 name: "[のだつ] t,c{99,4}",
606 total: 99,
607 current: 4,
608 want: " [のだつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつ…] ",
609 },
610 {
611 style: BarStyle().Lbound("[").Filler("の").Tip("だ").Padding("つ").Rbound("]"),
612 name: "[のだつ] t,c{99,5}",
613 total: 99,
614 current: 5,
615 want: " [のだつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつ…] ",
616 },
617 {
618 style: BarStyle().Lbound("[").Filler("の").Tip("だ").Padding("つ").Rbound("]"),
619 name: "[のだつ] t,c{99,6}",
620 total: 99,
621 current: 6,
622 want: " [ののだつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつ…] ",
623 },
624 {
625 style: BarStyle().Lbound("[").Filler("の").Tip("だ").Padding("つ").Rbound("]").Reverse(),
626 name: "[のだつ] t,c{99,6}rev",
627 total: 99,
628 current: 6,
629 want: " […つつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつだのの] ",
630 },
631 },
632 100: {
633 {
634 name: "t,c{100,0}",
635 total: 100,
636 current: 0,
637 want: " [------------------------------------------------------------------------------------------------] ",
638 },
639 {
640 name: "t,c{100,0}trim",
641 total: 100,
642 current: 0,
643 trim: true,
644 want: "[--------------------------------------------------------------------------------------------------]",
645 },
646 {
647 name: "t,c{100,1}",
648 total: 100,
649 current: 1,
650 want: " [>-----------------------------------------------------------------------------------------------] ",
651 },
652 {
653 name: "t,c{100,1}trim",
654 total: 100,
655 current: 1,
656 trim: true,
657 want: "[>-------------------------------------------------------------------------------------------------]",
658 },
659 {
660 name: "t,c{100,99}",
661 total: 100,
662 current: 99,
663 want: " [==============================================================================================>-] ",
664 },
665 {
666 name: "t,c{100,99}trim",
667 total: 100,
668 current: 99,
669 trim: true,
670 want: "[================================================================================================>-]",
671 },
672 {
673 name: "t,c{100,100}",
674 total: 100,
675 current: 100,
676 want: " [===============================================================================================>] ",
677 },
678 {
679 name: "t,c{100,100}trim",
680 total: 100,
681 current: 100,
682 trim: true,
683 want: "[=================================================================================================>]",
684 },
685 {
686 name: "t,c,r{100,100,100}trim",
687 total: 100,
688 current: 100,
689 refill: 100,
690 trim: true,
691 want: "[+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>]",
692 },
693 {
694 name: "t,c{100,33}",
695 total: 100,
696 current: 33,
697 want: " [===============================>----------------------------------------------------------------] ",
698 },
699 {
700 name: "t,c{100,33}trim",
701 total: 100,
702 current: 33,
703 trim: true,
704 want: "[===============================>------------------------------------------------------------------]",
705 },
706 {
707 style: BarStyle().Tip("<").Reverse(),
708 name: "t,c{100,33}trim,rev",
709 total: 100,
710 current: 33,
711 trim: true,
712 want: "[------------------------------------------------------------------<===============================]",
713 },
714 {
715 name: "t,c,r{100,33,33}",
716 total: 100,
717 current: 33,
718 refill: 33,
719 want: " [+++++++++++++++++++++++++++++++>----------------------------------------------------------------] ",
720 },
721 {
722 name: "t,c,r{100,33,33}trim",
723 total: 100,
724 current: 33,
725 refill: 33,
726 trim: true,
727 want: "[+++++++++++++++++++++++++++++++>------------------------------------------------------------------]",
728 },
729 {
730 style: BarStyle().Tip("<").Reverse(),
731 name: "t,c,r{100,33,33}trim,rev",
732 total: 100,
733 current: 33,
734 refill: 33,
735 trim: true,
736 want: "[------------------------------------------------------------------<+++++++++++++++++++++++++++++++]",
737 },
738 {
739 name: "t,c,r{100,40,33}",
740 total: 100,
741 current: 40,
742 refill: 33,
743 want: " [++++++++++++++++++++++++++++++++=====>----------------------------------------------------------] ",
744 },
745 {
746 name: "t,c,r{100,40,33}trim",
747 total: 100,
748 current: 40,
749 refill: 33,
750 trim: true,
751 want: "[++++++++++++++++++++++++++++++++======>-----------------------------------------------------------]",
752 },
753 {
754 style: BarStyle().Tip("<").Reverse(),
755 name: "t,c,r{100,40,33},rev",
756 total: 100,
757 current: 40,
758 refill: 33,
759 want: " [----------------------------------------------------------<=====++++++++++++++++++++++++++++++++] ",
760 },
761 {
762 style: BarStyle().Tip("<").Reverse(),
763 name: "t,c,r{100,40,33}trim,rev",
764 total: 100,
765 current: 40,
766 refill: 33,
767 trim: true,
768 want: "[-----------------------------------------------------------<======++++++++++++++++++++++++++++++++]",
769 },
770 },
771 }
772
773 var tmpBuf bytes.Buffer
774 for tw, cases := range testSuite {
775 for _, tc := range cases {
776 if tc.style == nil {
777 tc.style = BarStyle()
778 }
779 s := newTestState(NewBarFiller(tc.style.Inclusive(0)))
780 s.reqWidth = tc.barWidth
781 s.total = tc.total
782 s.current = tc.current
783 s.trimSpace = tc.trim
784 s.refill = tc.refill
785 tmpBuf.Reset()
786 tmpBuf.ReadFrom(s.draw(newStatistics(tw, s)))
787 by := tmpBuf.Bytes()
788
789 got := string(by[:len(by)-1])
790 if !utf8.ValidString(got) {
791 t.Fail()
792 }
793 if got != tc.want {
794 t.Errorf("termWidth:%d %q want: %q %d, got: %q %d\n", tw, tc.name, tc.want, utf8.RuneCountInString(tc.want), got, utf8.RuneCountInString(got))
795 }
796 }
797 }
798 }
799
415800 func newTestState(filler BarFiller) *bState {
416801 s := &bState{
417802 filler: filler,