Codebase list golang-github-vbauerster-mpb / c70540e
decorators: more descriptive params Vladimir Bauer 8 years ago
1 changed file(s) with 16 addition(s) and 16 deletion(s). Raw diff Collapse all Expand all
4444 }
4545
4646 // DecoratorFunc is a function that can be prepended and appended to the progress bar
47 type DecoratorFunc func(s *Statistics, myWidth chan<- int, maxWidth <-chan int) string
47 type DecoratorFunc func(s *Statistics, widthAccumulator chan<- int, widthDistributor <-chan int) string
4848
4949 // Name deprecated, use StaticName instead
5050 func Name(name string, minWidth int, conf byte) DecoratorFunc {
7070 format += "-"
7171 }
7272 format += "%ds"
73 return func(s *Statistics, myWidth chan<- int, maxWidth <-chan int) string {
73 return func(s *Statistics, widthAccumulator chan<- int, widthDistributor <-chan int) string {
7474 name := nameFn(s)
7575 if (conf & DwidthSync) != 0 {
76 myWidth <- utf8.RuneCountInString(name)
77 max := <-maxWidth
76 widthAccumulator <- utf8.RuneCountInString(name)
77 max := <-widthDistributor
7878 if (conf & DextraSpace) != 0 {
7979 max++
8080 }
112112 format += "-"
113113 }
114114 format += "%ds"
115 return func(s *Statistics, myWidth chan<- int, maxWidth <-chan int) string {
115 return func(s *Statistics, widthAccumulator chan<- int, widthDistributor <-chan int) string {
116116 var str string
117117 switch unit {
118118 case Unit_KiB:
123123 str = fmt.Sprintf(pairFormat, s.Current, s.Total)
124124 }
125125 if (conf & DwidthSync) != 0 {
126 myWidth <- utf8.RuneCountInString(str)
127 max := <-maxWidth
126 widthAccumulator <- utf8.RuneCountInString(str)
127 max := <-widthDistributor
128128 if (conf & DextraSpace) != 0 {
129129 max++
130130 }
143143 format += "-"
144144 }
145145 format += "%ds"
146 return func(s *Statistics, myWidth chan<- int, maxWidth <-chan int) string {
146 return func(s *Statistics, widthAccumulator chan<- int, widthDistributor <-chan int) string {
147147 str := fmt.Sprint(time.Duration(s.Eta().Seconds()) * time.Second)
148148 if (conf & DwidthSync) != 0 {
149 myWidth <- utf8.RuneCountInString(str)
150 max := <-maxWidth
149 widthAccumulator <- utf8.RuneCountInString(str)
150 max := <-widthDistributor
151151 if (conf & DextraSpace) != 0 {
152152 max++
153153 }
166166 format += "-"
167167 }
168168 format += "%ds"
169 return func(s *Statistics, myWidth chan<- int, maxWidth <-chan int) string {
169 return func(s *Statistics, widthAccumulator chan<- int, widthDistributor <-chan int) string {
170170 str := fmt.Sprint(time.Duration(s.TimeElapsed.Seconds()) * time.Second)
171171 if (conf & DwidthSync) != 0 {
172 myWidth <- utf8.RuneCountInString(str)
173 max := <-maxWidth
172 widthAccumulator <- utf8.RuneCountInString(str)
173 max := <-widthDistributor
174174 if (conf & DextraSpace) != 0 {
175175 max++
176176 }
189189 format += "-"
190190 }
191191 format += "%ds"
192 return func(s *Statistics, myWidth chan<- int, maxWidth <-chan int) string {
192 return func(s *Statistics, widthAccumulator chan<- int, widthDistributor <-chan int) string {
193193 str := fmt.Sprintf("%d %%", CalcPercentage(s.Total, s.Current, 100))
194194 if (conf & DwidthSync) != 0 {
195 myWidth <- utf8.RuneCountInString(str)
196 max := <-maxWidth
195 widthAccumulator <- utf8.RuneCountInString(str)
196 max := <-widthDistributor
197197 if (conf & DextraSpace) != 0 {
198198 max++
199199 }