| 7 | 7 |
)
|
| 8 | 8 |
|
| 9 | 9 |
const (
|
| 10 | |
// DidentRight bit specifies identation direction.
|
|
10 |
// DidentRight specifies identation direction.
|
| 11 | 11 |
// |foo |b | With DidentRight
|
| 12 | 12 |
// | foo| b| Without DidentRight
|
| 13 | 13 |
DidentRight = 1 << iota
|
|
| 16 | 16 |
// Effective on multiple bars only.
|
| 17 | 17 |
DwidthSync
|
| 18 | 18 |
|
| 19 | |
// DextraSpace bit adds extra space, makes sense with DwidthSync only.
|
|
19 |
// DextraSpace adds extra space, makes sense with DwidthSync only.
|
| 20 | 20 |
// When DidentRight bit set, the space will be added to the right,
|
| 21 | 21 |
// otherwise to the left.
|
| 22 | 22 |
DextraSpace
|
| 23 | |
|
| 24 | |
// DslowMotion bit instructs decorator to skip refreshing its output
|
| 25 | |
// every second tick. Normally not necessary, but if flickering is too fast,
|
| 26 | |
// you may try it out.
|
| 27 | |
DslowMotion
|
| 28 | 23 |
|
| 29 | 24 |
// DSyncSpace is shortcut for DwidthSync|DextraSpace
|
| 30 | 25 |
DSyncSpace = DwidthSync | DextraSpace
|
|
| 98 | 93 |
format += "-"
|
| 99 | 94 |
}
|
| 100 | 95 |
format += "%ds"
|
| 101 | |
count, times := 0, 1
|
| 102 | |
if (conf & DslowMotion) != 0 {
|
| 103 | |
times++
|
| 104 | |
}
|
| 105 | |
var out string
|
| 106 | |
return func(s *Statistics, widthAccumulator chan<- int, widthDistributor <-chan int) string {
|
| 107 | |
if count == 0 || s.Completed {
|
| 108 | |
count = times
|
| 109 | |
out = messageFn(s)
|
| 110 | |
}
|
| 111 | |
count--
|
| 112 | |
if (conf & DwidthSync) != 0 {
|
| 113 | |
widthAccumulator <- utf8.RuneCountInString(out)
|
| 114 | |
max := <-widthDistributor
|
| 115 | |
if (conf & DextraSpace) != 0 {
|
| 116 | |
max++
|
| 117 | |
}
|
| 118 | |
return fmt.Sprintf(fmt.Sprintf(format, max), out)
|
| 119 | |
}
|
| 120 | |
return fmt.Sprintf(fmt.Sprintf(format, width), out)
|
|
96 |
return func(s *Statistics, widthAccumulator chan<- int, widthDistributor <-chan int) string {
|
|
97 |
name := messageFn(s)
|
|
98 |
if (conf & DwidthSync) != 0 {
|
|
99 |
widthAccumulator <- utf8.RuneCountInString(name)
|
|
100 |
max := <-widthDistributor
|
|
101 |
if (conf & DextraSpace) != 0 {
|
|
102 |
max++
|
|
103 |
}
|
|
104 |
return fmt.Sprintf(fmt.Sprintf(format, max), name)
|
|
105 |
}
|
|
106 |
return fmt.Sprintf(fmt.Sprintf(format, width), name)
|
| 121 | 107 |
}
|
| 122 | 108 |
}
|
| 123 | 109 |
|
|
| 168 | 154 |
format += "-"
|
| 169 | 155 |
}
|
| 170 | 156 |
format += "%ds"
|
| 171 | |
count, times := 0, 1
|
| 172 | |
if (conf & DslowMotion) != 0 {
|
| 173 | |
times++
|
| 174 | |
}
|
| 175 | |
var out string
|
| 176 | |
return func(s *Statistics, widthAccumulator chan<- int, widthDistributor <-chan int) string {
|
| 177 | |
if count == 0 || s.Completed {
|
| 178 | |
count = times
|
| 179 | |
switch unit {
|
| 180 | |
case unitKiB:
|
| 181 | |
out = fmt.Sprintf(pairFormat, CounterKiB(s.Current), CounterKiB(s.Total))
|
| 182 | |
case unitKB:
|
| 183 | |
out = fmt.Sprintf(pairFormat, CounterKB(s.Current), CounterKB(s.Total))
|
| 184 | |
default:
|
| 185 | |
out = fmt.Sprintf(pairFormat, s.Current, s.Total)
|
| 186 | |
}
|
| 187 | |
}
|
| 188 | |
count--
|
| 189 | |
if (conf & DwidthSync) != 0 {
|
| 190 | |
widthAccumulator <- utf8.RuneCountInString(out)
|
| 191 | |
max := <-widthDistributor
|
| 192 | |
if (conf & DextraSpace) != 0 {
|
| 193 | |
max++
|
| 194 | |
}
|
| 195 | |
return fmt.Sprintf(fmt.Sprintf(format, max), out)
|
| 196 | |
}
|
| 197 | |
return fmt.Sprintf(fmt.Sprintf(format, width), out)
|
|
157 |
return func(s *Statistics, widthAccumulator chan<- int, widthDistributor <-chan int) string {
|
|
158 |
var str string
|
|
159 |
switch unit {
|
|
160 |
case unitKiB:
|
|
161 |
str = fmt.Sprintf(pairFormat, CounterKiB(s.Current), CounterKiB(s.Total))
|
|
162 |
case unitKB:
|
|
163 |
str = fmt.Sprintf(pairFormat, CounterKB(s.Current), CounterKB(s.Total))
|
|
164 |
default:
|
|
165 |
str = fmt.Sprintf(pairFormat, s.Current, s.Total)
|
|
166 |
}
|
|
167 |
if (conf & DwidthSync) != 0 {
|
|
168 |
widthAccumulator <- utf8.RuneCountInString(str)
|
|
169 |
max := <-widthDistributor
|
|
170 |
if (conf & DextraSpace) != 0 {
|
|
171 |
max++
|
|
172 |
}
|
|
173 |
return fmt.Sprintf(fmt.Sprintf(format, max), str)
|
|
174 |
}
|
|
175 |
return fmt.Sprintf(fmt.Sprintf(format, width), str)
|
| 198 | 176 |
}
|
| 199 | 177 |
}
|
| 200 | 178 |
|
|
| 209 | 187 |
format += "-"
|
| 210 | 188 |
}
|
| 211 | 189 |
format += "%ds"
|
| 212 | |
count, times := 0, 1
|
| 213 | |
if (conf & DslowMotion) != 0 {
|
| 214 | |
times++
|
| 215 | |
}
|
| 216 | |
var out string
|
| 217 | |
return func(s *Statistics, widthAccumulator chan<- int, widthDistributor <-chan int) string {
|
| 218 | |
if count == 0 || s.Completed {
|
| 219 | |
count = times
|
| 220 | |
out = fmt.Sprint(time.Duration(s.Eta().Seconds()) * time.Second)
|
| 221 | |
}
|
| 222 | |
count--
|
| 223 | |
if (conf & DwidthSync) != 0 {
|
| 224 | |
widthAccumulator <- utf8.RuneCountInString(out)
|
| 225 | |
max := <-widthDistributor
|
| 226 | |
if (conf & DextraSpace) != 0 {
|
| 227 | |
max++
|
| 228 | |
}
|
| 229 | |
return fmt.Sprintf(fmt.Sprintf(format, max), out)
|
| 230 | |
}
|
| 231 | |
return fmt.Sprintf(fmt.Sprintf(format, width), out)
|
|
190 |
return func(s *Statistics, widthAccumulator chan<- int, widthDistributor <-chan int) string {
|
|
191 |
str := fmt.Sprint(time.Duration(s.Eta().Seconds()) * time.Second)
|
|
192 |
if (conf & DwidthSync) != 0 {
|
|
193 |
widthAccumulator <- utf8.RuneCountInString(str)
|
|
194 |
max := <-widthDistributor
|
|
195 |
if (conf & DextraSpace) != 0 {
|
|
196 |
max++
|
|
197 |
}
|
|
198 |
return fmt.Sprintf(fmt.Sprintf(format, max), str)
|
|
199 |
}
|
|
200 |
return fmt.Sprintf(fmt.Sprintf(format, width), str)
|
| 232 | 201 |
}
|
| 233 | 202 |
}
|
| 234 | 203 |
|
|
| 243 | 212 |
format += "-"
|
| 244 | 213 |
}
|
| 245 | 214 |
format += "%ds"
|
| 246 | |
count, times := 0, 1
|
| 247 | |
if (conf & DslowMotion) != 0 {
|
| 248 | |
times++
|
| 249 | |
}
|
| 250 | |
var out string
|
| 251 | |
return func(s *Statistics, widthAccumulator chan<- int, widthDistributor <-chan int) string {
|
| 252 | |
if count == 0 || s.Completed {
|
| 253 | |
count = times
|
| 254 | |
out = fmt.Sprint(time.Duration(s.TimeElapsed.Seconds()) * time.Second)
|
| 255 | |
}
|
| 256 | |
count--
|
| 257 | |
if (conf & DwidthSync) != 0 {
|
| 258 | |
widthAccumulator <- utf8.RuneCountInString(out)
|
| 259 | |
max := <-widthDistributor
|
| 260 | |
if (conf & DextraSpace) != 0 {
|
| 261 | |
max++
|
| 262 | |
}
|
| 263 | |
return fmt.Sprintf(fmt.Sprintf(format, max), out)
|
| 264 | |
}
|
| 265 | |
return fmt.Sprintf(fmt.Sprintf(format, width), out)
|
|
215 |
return func(s *Statistics, widthAccumulator chan<- int, widthDistributor <-chan int) string {
|
|
216 |
str := fmt.Sprint(time.Duration(s.TimeElapsed.Seconds()) * time.Second)
|
|
217 |
if (conf & DwidthSync) != 0 {
|
|
218 |
widthAccumulator <- utf8.RuneCountInString(str)
|
|
219 |
max := <-widthDistributor
|
|
220 |
if (conf & DextraSpace) != 0 {
|
|
221 |
max++
|
|
222 |
}
|
|
223 |
return fmt.Sprintf(fmt.Sprintf(format, max), str)
|
|
224 |
}
|
|
225 |
return fmt.Sprintf(fmt.Sprintf(format, width), str)
|
| 266 | 226 |
}
|
| 267 | 227 |
}
|
| 268 | 228 |
|
|
| 277 | 237 |
format += "-"
|
| 278 | 238 |
}
|
| 279 | 239 |
format += "%ds"
|
| 280 | |
count, times := 0, 1
|
| 281 | |
if (conf & DslowMotion) != 0 {
|
| 282 | |
times++
|
| 283 | |
}
|
| 284 | |
var out string
|
| 285 | |
return func(s *Statistics, widthAccumulator chan<- int, widthDistributor <-chan int) string {
|
| 286 | |
if count == 0 || s.Completed {
|
| 287 | |
count = times
|
| 288 | |
out = fmt.Sprintf("%d %%", CalcPercentage(s.Total, s.Current, 100))
|
| 289 | |
}
|
| 290 | |
count--
|
| 291 | |
if (conf & DwidthSync) != 0 {
|
| 292 | |
widthAccumulator <- utf8.RuneCountInString(out)
|
| 293 | |
max := <-widthDistributor
|
| 294 | |
if (conf & DextraSpace) != 0 {
|
| 295 | |
max++
|
| 296 | |
}
|
| 297 | |
return fmt.Sprintf(fmt.Sprintf(format, max), out)
|
| 298 | |
}
|
| 299 | |
return fmt.Sprintf(fmt.Sprintf(format, width), out)
|
|
240 |
return func(s *Statistics, widthAccumulator chan<- int, widthDistributor <-chan int) string {
|
|
241 |
str := fmt.Sprintf("%d %%", CalcPercentage(s.Total, s.Current, 100))
|
|
242 |
if (conf & DwidthSync) != 0 {
|
|
243 |
widthAccumulator <- utf8.RuneCountInString(str)
|
|
244 |
max := <-widthDistributor
|
|
245 |
if (conf & DextraSpace) != 0 {
|
|
246 |
max++
|
|
247 |
}
|
|
248 |
return fmt.Sprintf(fmt.Sprintf(format, max), str)
|
|
249 |
}
|
|
250 |
return fmt.Sprintf(fmt.Sprintf(format, width), str)
|
| 300 | 251 |
}
|
| 301 | 252 |
}
|
| 302 | 253 |
|