BarWidth
Vladimir Bauer
7 years ago
| 46 | 46 | } |
| 47 | 47 | } |
| 48 | 48 | |
| 49 | // BarWidth sets bar width independent of the container. | |
| 50 | func BarWidth(width int) BarOption { | |
| 51 | return func(s *bState) { | |
| 52 | s.width = width | |
| 53 | } | |
| 54 | } | |
| 55 | ||
| 49 | 56 | // BarRemoveOnComplete is a flag, if set whole bar line will be removed |
| 50 | // on complete event. If both BarRemoveOnComplete and BarClearOnComplete | |
| 57 | // on complete event. If both BarRemoveOnComplete and BarClearOnComplete | |
| 51 | 58 | // are set, first bar section gets cleared and then whole bar line |
| 52 | 59 | // gets removed completely. |
| 53 | 60 | func BarRemoveOnComplete() BarOption { |
| 57 | 64 | } |
| 58 | 65 | |
| 59 | 66 | // BarReplaceOnComplete is indicator for delayed bar start, after the |
| 60 | // `runningBar` is complete. To achieve bar replacement effect, | |
| 67 | // `runningBar` is complete. To achieve bar replacement effect, | |
| 61 | 68 | // `runningBar` should has its `BarRemoveOnComplete` option set. |
| 62 | 69 | func BarReplaceOnComplete(runningBar *Bar) BarOption { |
| 63 | 70 | return func(s *bState) { |
| 66 | 73 | } |
| 67 | 74 | |
| 68 | 75 | // BarClearOnComplete is a flag, if set will clear bar section on |
| 69 | // complete event. If you need to remove a whole bar line, refer to | |
| 76 | // complete event. If you need to remove a whole bar line, refer to | |
| 70 | 77 | // BarRemoveOnComplete. |
| 71 | 78 | func BarClearOnComplete() BarOption { |
| 72 | 79 | return func(s *bState) { |
| 74 | 81 | } |
| 75 | 82 | } |
| 76 | 83 | |
| 77 | // BarPriority sets bar's priority. | |
| 78 | // Zero is highest priority, i.e. bar will be on top. If | |
| 79 | // `BarReplaceOnComplete` option is supplied, this option is ignored. | |
| 84 | // BarPriority sets bar's priority. Zero is highest priority, i.e. bar | |
| 85 | // will be on top. If `BarReplaceOnComplete` option is supplied, this | |
| 86 | // option is ignored. | |
| 80 | 87 | func BarPriority(priority int) BarOption { |
| 81 | 88 | return func(s *bState) { |
| 82 | 89 | s.priority = priority |
| 84 | 91 | } |
| 85 | 92 | |
| 86 | 93 | // BarNewLineExtend takes user defined efn, which gets called each |
| 87 | // render cycle. Any write to provided writer of efn, will appear on | |
| 94 | // render cycle. Any write to provided writer of efn, will appear on | |
| 88 | 95 | // new line of respective bar. |
| 89 | 96 | func BarNewLineExtend(efn func(io.Writer, *decor.Statistics)) BarOption { |
| 90 | 97 | return func(s *bState) { |
| 140 | 147 | } |
| 141 | 148 | |
| 142 | 149 | // MakeFillerTypeSpecificBarOption makes BarOption specific to Filler's |
| 143 | // actual type. If you implement your own Filler, so most probably | |
| 144 | // you'll need this. See BarStyle or SpinnerStyle for example. | |
| 150 | // actual type. If you implement your own Filler, so most probably | |
| 151 | // you'll need this. See BarStyle or SpinnerStyle for example. | |
| 145 | 152 | func MakeFillerTypeSpecificBarOption( |
| 146 | 153 | typeChecker func(Filler) (interface{}, bool), |
| 147 | 154 | cb func(interface{}), |
| 152 | 159 | } |
| 153 | 160 | } |
| 154 | 161 | } |
| 162 | ||
| 163 | // OptionOnCondition returns option when condition evaluates to true. | |
| 164 | func OptionOnCondition(option BarOption, condition func() bool) BarOption { | |
| 165 | if condition() { | |
| 166 | return option | |
| 167 | } | |
| 168 | return nil | |
| 169 | } | |