Codebase list golang-github-vbauerster-mpb / b630a4b
refactoring: bar_filler_bar: remove unnecessary methods Vladimir Bauer 5 years ago
1 changed file(s) with 13 addition(s) and 15 deletion(s). Raw diff Collapse all Expand all
6060 rwidth: make([]int, len(DefaultBarStyle)),
6161 reverse: reverse,
6262 }
63 bf.SetStyle(style)
63 bf.parse(DefaultBarStyle)
64 if style != DefaultBarStyle {
65 bf.parse(style)
66 }
6467 return bf
6568 }
6669
67 func (s *barFiller) SetStyle(style string) {
70 func (s *barFiller) parse(style string) {
6871 if !utf8.ValidString(style) {
6972 panic("invalid bar style")
7073 }
71 if style == "" {
72 style = DefaultBarStyle
73 }
74 src := make([][]byte, utf8.RuneCountInString(style))
74 rcount := utf8.RuneCountInString(style)
75 srcFormat := make([][]byte, rcount)
76 srcRwidth := make([]int, rcount)
7577 i := 0
7678 for _, r := range style {
77 s.rwidth[i] = runewidth.RuneWidth(r)
78 src[i] = []byte(string(r))
79 srcRwidth[i] = runewidth.RuneWidth(r)
80 srcFormat[i] = []byte(string(r))
7981 i++
8082 }
81 copy(s.format, src)
82 s.SetReverse(s.reverse)
83 }
84
85 func (s *barFiller) SetReverse(reverse bool) {
86 if reverse {
83 copy(s.format, srcFormat)
84 copy(s.rwidth, srcRwidth)
85 if s.reverse {
8786 s.tip = s.format[rRevTip]
8887 s.flush = reverseFlush
8988 } else {
9089 s.tip = s.format[rTip]
9190 s.flush = regularFlush
9291 }
93 s.reverse = reverse
9492 }
9593
9694 func (s *barFiller) Fill(w io.Writer, reqWidth int, stat decor.Statistics) {