refactoring: bar_filler_bar: remove unnecessary methods
Vladimir Bauer
5 years ago
| 60 | 60 | rwidth: make([]int, len(DefaultBarStyle)), |
| 61 | 61 | reverse: reverse, |
| 62 | 62 | } |
| 63 | bf.SetStyle(style) | |
| 63 | bf.parse(DefaultBarStyle) | |
| 64 | if style != DefaultBarStyle { | |
| 65 | bf.parse(style) | |
| 66 | } | |
| 64 | 67 | return bf |
| 65 | 68 | } |
| 66 | 69 | |
| 67 | func (s *barFiller) SetStyle(style string) { | |
| 70 | func (s *barFiller) parse(style string) { | |
| 68 | 71 | if !utf8.ValidString(style) { |
| 69 | 72 | panic("invalid bar style") |
| 70 | 73 | } |
| 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) | |
| 75 | 77 | i := 0 |
| 76 | 78 | 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)) | |
| 79 | 81 | i++ |
| 80 | 82 | } |
| 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 { | |
| 87 | 86 | s.tip = s.format[rRevTip] |
| 88 | 87 | s.flush = reverseFlush |
| 89 | 88 | } else { |
| 90 | 89 | s.tip = s.format[rTip] |
| 91 | 90 | s.flush = regularFlush |
| 92 | 91 | } |
| 93 | s.reverse = reverse | |
| 94 | 92 | } |
| 95 | 93 | |
| 96 | 94 | func (s *barFiller) Fill(w io.Writer, reqWidth int, stat decor.Statistics) { |