remove BarOptions which modify underlying BarFiller
Vladimir Bauer
5 years ago
| 131 | 131 | } |
| 132 | 132 | } |
| 133 | 133 | |
| 134 | // TrimSpace is an alias to BarFillerTrim. | |
| 135 | func TrimSpace() BarOption { | |
| 136 | return BarFillerTrim() | |
| 137 | } | |
| 138 | ||
| 139 | // BarStyle overrides mpb.DefaultBarStyle which is "[=>-]<+". | |
| 140 | // It's ok to pass string containing just 5 runes, for example "╢▌▌░╟", | |
| 141 | // if you don't need to override '<' (reverse tip) and '+' (refill rune). | |
| 142 | func BarStyle(style string) BarOption { | |
| 143 | if style == "" { | |
| 144 | return nil | |
| 145 | } | |
| 146 | type styleSetter interface { | |
| 147 | SetStyle(string) | |
| 148 | } | |
| 149 | return func(s *bState) { | |
| 150 | if t, ok := s.filler.(styleSetter); ok { | |
| 151 | t.SetStyle(style) | |
| 152 | } | |
| 153 | } | |
| 154 | } | |
| 155 | ||
| 156 | 134 | // BarNoPop disables bar pop out of container. Effective when |
| 157 | 135 | // PopCompletedMode of container is enabled. |
| 158 | 136 | func BarNoPop() BarOption { |
| 159 | 137 | return func(s *bState) { |
| 160 | 138 | s.noPop = true |
| 161 | } | |
| 162 | } | |
| 163 | ||
| 164 | // BarReverse reverse mode, bar will progress from right to left. | |
| 165 | func BarReverse() BarOption { | |
| 166 | type revSetter interface { | |
| 167 | SetReverse(bool) | |
| 168 | } | |
| 169 | return func(s *bState) { | |
| 170 | if t, ok := s.filler.(revSetter); ok { | |
| 171 | t.SetReverse(true) | |
| 172 | } | |
| 173 | } | |
| 174 | } | |
| 175 | ||
| 176 | // SpinnerStyle sets custom spinner style. | |
| 177 | // Effective when Filler type is spinner. | |
| 178 | func SpinnerStyle(frames []string) BarOption { | |
| 179 | if len(frames) == 0 { | |
| 180 | return nil | |
| 181 | } | |
| 182 | chk := func(filler BarFiller) (interface{}, bool) { | |
| 183 | t, ok := filler.(*spinnerFiller) | |
| 184 | return t, ok | |
| 185 | } | |
| 186 | cb := func(t interface{}) { | |
| 187 | t.(*spinnerFiller).frames = frames | |
| 188 | } | |
| 189 | return MakeFillerTypeSpecificBarOption(chk, cb) | |
| 190 | } | |
| 191 | ||
| 192 | // MakeFillerTypeSpecificBarOption makes BarOption specific to Filler's | |
| 193 | // actual type. If you implement your own Filler, so most probably | |
| 194 | // you'll need this. See BarStyle or SpinnerStyle for example. | |
| 195 | func MakeFillerTypeSpecificBarOption( | |
| 196 | typeChecker func(BarFiller) (interface{}, bool), | |
| 197 | cb func(interface{}), | |
| 198 | ) BarOption { | |
| 199 | return func(s *bState) { | |
| 200 | if t, ok := typeChecker(s.filler); ok { | |
| 201 | cb(t) | |
| 202 | } | |
| 203 | 139 | } |
| 204 | 140 | } |
| 205 | 141 |