| 95 | 95 |
}
|
| 96 | 96 |
|
| 97 | 97 |
// CountersNoUnit returns raw counters decorator
|
| 98 | |
// If you set `DwidthSync` bit in `conf` param, `minWidth` param is ignored.
|
| 99 | |
// `DwidthSync` is effective with multiple bars only, if set decorator will participate
|
| 100 | |
// in width synchronization process with other decorators in the same column group.
|
|
98 |
//
|
|
99 |
// `pairFormat` printf compatible verbs for current and total, like "%f" or "%d".
|
|
100 |
//
|
|
101 |
// `minWidth` minimum width to apply, if `DwidthSync` bit is not set.
|
|
102 |
//
|
|
103 |
// `conf` bit set config, [DidentRight|DwidthSync|DextraSpace]
|
| 101 | 104 |
func CountersNoUnit(pairFormat string, minWidth, conf int) DecoratorFunc {
|
| 102 | |
return Counters(pairFormat, 0, minWidth, conf)
|
|
105 |
return counters(pairFormat, 0, minWidth, conf)
|
| 103 | 106 |
}
|
| 104 | 107 |
|
| 105 | 108 |
// CountersKibiByte returns human friendly byte counters decorator, where counters unit is multiple by 1024.
|
|
| 112 | 115 |
//
|
| 113 | 116 |
// pairFormat example:
|
| 114 | 117 |
//
|
| 115 | |
// `"%.1f / %.1f" = "1.0MiB / 12.0MiB"` or `"% .1f / % .1f" = "1.0 MiB / 12.0 MiB"`.
|
|
118 |
// "%.1f / %.1f" = "1.0MiB / 12.0MiB" or "% .1f / % .1f" = "1.0 MiB / 12.0 MiB"
|
| 116 | 119 |
func CountersKibiByte(pairFormat string, minWidth, conf int) DecoratorFunc {
|
| 117 | |
return Counters(pairFormat, Unit_KiB, minWidth, conf)
|
| 118 | |
}
|
| 119 | |
|
| 120 | |
// CountersKiloByte returns human friendly byte counters decorator, where
|
| 121 | |
// counters unit is multiple by 1000.
|
| 122 | |
// `pairFormat` must contain two printf compatible verbs, like "%f" or "%d".
|
| 123 | |
// First verb substituted with Current, second one with Total.
|
| 124 | |
// Example: `"%.1f / %.1f" = "1.0MB / 12.0MB"` or `"% .1f / % .1f" = "1.0 MB / 12.0 MB"`.
|
| 125 | |
// If you set `DwidthSync` bit in `conf` param, `minWidth` param is ignored.
|
| 126 | |
// `DwidthSync` is effective with multiple bars only, if set decorator will participate
|
| 127 | |
// in width synchronization process with other decorators in the same column group.
|
|
120 |
return counters(pairFormat, unitKiB, minWidth, conf)
|
|
121 |
}
|
|
122 |
|
|
123 |
// CountersKiloByte returns human friendly byte counters decorator, where counters unit is multiple by 1000.
|
|
124 |
//
|
|
125 |
// `pairFormat` printf compatible verbs for current and total, like "%f" or "%d".
|
|
126 |
//
|
|
127 |
// `minWidth` minimum width to apply, if `DwidthSync` bit is not set.
|
|
128 |
//
|
|
129 |
// `conf` bit set config, [DidentRight|DwidthSync|DextraSpace]
|
|
130 |
//
|
|
131 |
// pairFormat example:
|
|
132 |
//
|
|
133 |
// "%.1f / %.1f" = "1.0MB / 12.0MB" or "% .1f / % .1f" = "1.0 MB / 12.0 MB"
|
| 128 | 134 |
func CountersKiloByte(pairFormat string, minWidth, conf int) DecoratorFunc {
|
| 129 | |
return Counters(pairFormat, Unit_kB, minWidth, conf)
|
| 130 | |
}
|
| 131 | |
|
| 132 | |
// Counters provides basic counters decorator.
|
| 133 | |
// `pairFormat` must contain two printf compatible verbs, like "%f" or "%d".
|
| 134 | |
// First verb substituted with Current, second one with Total.
|
| 135 | |
// Example: `"%.1f / %.1f" = "1.0MiB / 12.0MiB"` or `"% .1f / % .1f" = "1.0 MiB / 12.0 MiB"`.
|
| 136 | |
// `unit` is one of decor.Unit_KiB/decor.Unit_kB or just zero if you need raw unitless numbers.
|
| 137 | |
// If you set `DwidthSync` bit in `conf` param, `minWidth` param is ignored.
|
| 138 | |
// `DwidthSync` is effective with multiple bars only, if set decorator will participate
|
| 139 | |
// in width synchronization process with other decorators in the same column group.
|
| 140 | |
func Counters(pairFormat string, unit Unit, minWidth, conf int) DecoratorFunc {
|
|
135 |
return counters(pairFormat, unitKB, minWidth, conf)
|
|
136 |
}
|
|
137 |
|
|
138 |
func counters(pairFormat string, unit counterUnit, minWidth, conf int) DecoratorFunc {
|
| 141 | 139 |
format := "%%"
|
| 142 | 140 |
if (conf & DidentRight) != 0 {
|
| 143 | 141 |
format += "-"
|
|
| 146 | 144 |
return func(s *Statistics, widthAccumulator chan<- int, widthDistributor <-chan int) string {
|
| 147 | 145 |
var str string
|
| 148 | 146 |
switch unit {
|
| 149 | |
case Unit_KiB:
|
|
147 |
case unitKiB:
|
| 150 | 148 |
str = fmt.Sprintf(pairFormat, CounterKiB(s.Current), CounterKiB(s.Total))
|
| 151 | |
case Unit_kB:
|
|
149 |
case unitKB:
|
| 152 | 150 |
str = fmt.Sprintf(pairFormat, CounterKB(s.Current), CounterKB(s.Total))
|
| 153 | 151 |
default:
|
| 154 | 152 |
str = fmt.Sprintf(pairFormat, s.Current, s.Total)
|