| 37 | 37 |
// pairFmt="%f / %f" output: "1.000000MB / 12.000000MB"
|
| 38 | 38 |
// pairFmt="% f / % f" output: "1.000000 MB / 12.000000 MB"
|
| 39 | 39 |
func Counters(unit interface{}, pairFmt string, wcc ...WC) Decorator {
|
| 40 | |
if pairFmt == "" {
|
| 41 | |
pairFmt = "% d / % d"
|
| 42 | |
}
|
| 43 | |
producer := func() DecorFunc {
|
| 44 | |
switch unit.(type) {
|
| 45 | |
case SizeB1024:
|
|
40 |
producer := func() DecorFunc {
|
|
41 |
switch unit.(type) {
|
|
42 |
case SizeB1024:
|
|
43 |
if pairFmt == "" {
|
|
44 |
pairFmt = "% d / % d"
|
|
45 |
}
|
| 46 | 46 |
return func(s Statistics) string {
|
| 47 | 47 |
return fmt.Sprintf(pairFmt, SizeB1024(s.Current), SizeB1024(s.Total))
|
| 48 | 48 |
}
|
| 49 | 49 |
case SizeB1000:
|
|
50 |
if pairFmt == "" {
|
|
51 |
pairFmt = "% d / % d"
|
|
52 |
}
|
| 50 | 53 |
return func(s Statistics) string {
|
| 51 | 54 |
return fmt.Sprintf(pairFmt, SizeB1000(s.Current), SizeB1000(s.Total))
|
| 52 | 55 |
}
|
| 53 | 56 |
default:
|
|
57 |
if pairFmt == "" {
|
|
58 |
pairFmt = "%d / %d"
|
|
59 |
}
|
| 54 | 60 |
return func(s Statistics) string {
|
| 55 | 61 |
return fmt.Sprintf(pairFmt, s.Current, s.Total)
|
| 56 | 62 |
}
|
|
| 93 | 99 |
// format="%f" output: "12.000000MiB"
|
| 94 | 100 |
// format="% f" output: "12.000000 MiB"
|
| 95 | 101 |
func Total(unit interface{}, format string, wcc ...WC) Decorator {
|
| 96 | |
if format == "" {
|
| 97 | |
format = "% d"
|
| 98 | |
}
|
| 99 | |
producer := func() DecorFunc {
|
| 100 | |
switch unit.(type) {
|
| 101 | |
case SizeB1024:
|
|
102 |
producer := func() DecorFunc {
|
|
103 |
switch unit.(type) {
|
|
104 |
case SizeB1024:
|
|
105 |
if format == "" {
|
|
106 |
format = "% d"
|
|
107 |
}
|
| 102 | 108 |
return func(s Statistics) string {
|
| 103 | 109 |
return fmt.Sprintf(format, SizeB1024(s.Total))
|
| 104 | 110 |
}
|
| 105 | 111 |
case SizeB1000:
|
|
112 |
if format == "" {
|
|
113 |
format = "% d"
|
|
114 |
}
|
| 106 | 115 |
return func(s Statistics) string {
|
| 107 | 116 |
return fmt.Sprintf(format, SizeB1000(s.Total))
|
| 108 | 117 |
}
|
| 109 | 118 |
default:
|
|
119 |
if format == "" {
|
|
120 |
format = "%d"
|
|
121 |
}
|
| 110 | 122 |
return func(s Statistics) string {
|
| 111 | 123 |
return fmt.Sprintf(format, s.Total)
|
| 112 | 124 |
}
|
|
| 149 | 161 |
// format="%f" output: "12.000000MiB"
|
| 150 | 162 |
// format="% f" output: "12.000000 MiB"
|
| 151 | 163 |
func Current(unit interface{}, format string, wcc ...WC) Decorator {
|
| 152 | |
if format == "" {
|
| 153 | |
format = "% d"
|
| 154 | |
}
|
| 155 | |
producer := func() DecorFunc {
|
| 156 | |
switch unit.(type) {
|
| 157 | |
case SizeB1024:
|
|
164 |
producer := func() DecorFunc {
|
|
165 |
switch unit.(type) {
|
|
166 |
case SizeB1024:
|
|
167 |
if format == "" {
|
|
168 |
format = "% d"
|
|
169 |
}
|
| 158 | 170 |
return func(s Statistics) string {
|
| 159 | 171 |
return fmt.Sprintf(format, SizeB1024(s.Current))
|
| 160 | 172 |
}
|
| 161 | 173 |
case SizeB1000:
|
|
174 |
if format == "" {
|
|
175 |
format = "% d"
|
|
176 |
}
|
| 162 | 177 |
return func(s Statistics) string {
|
| 163 | 178 |
return fmt.Sprintf(format, SizeB1000(s.Current))
|
| 164 | 179 |
}
|
| 165 | 180 |
default:
|
|
181 |
if format == "" {
|
|
182 |
format = "%d"
|
|
183 |
}
|
| 166 | 184 |
return func(s Statistics) string {
|
| 167 | 185 |
return fmt.Sprintf(format, s.Current)
|
| 168 | 186 |
}
|
|
| 205 | 223 |
// format="%f" output: "12.000000MiB"
|
| 206 | 224 |
// format="% f" output: "12.000000 MiB"
|
| 207 | 225 |
func InvertedCurrent(unit interface{}, format string, wcc ...WC) Decorator {
|
| 208 | |
if format == "" {
|
| 209 | |
format = "% d"
|
| 210 | |
}
|
| 211 | |
producer := func() DecorFunc {
|
| 212 | |
switch unit.(type) {
|
| 213 | |
case SizeB1024:
|
|
226 |
producer := func() DecorFunc {
|
|
227 |
switch unit.(type) {
|
|
228 |
case SizeB1024:
|
|
229 |
if format == "" {
|
|
230 |
format = "% d"
|
|
231 |
}
|
| 214 | 232 |
return func(s Statistics) string {
|
| 215 | 233 |
return fmt.Sprintf(format, SizeB1024(s.Total-s.Current))
|
| 216 | 234 |
}
|
| 217 | 235 |
case SizeB1000:
|
|
236 |
if format == "" {
|
|
237 |
format = "% d"
|
|
238 |
}
|
| 218 | 239 |
return func(s Statistics) string {
|
| 219 | 240 |
return fmt.Sprintf(format, SizeB1000(s.Total-s.Current))
|
| 220 | 241 |
}
|
| 221 | 242 |
default:
|
|
243 |
if format == "" {
|
|
244 |
format = "%d"
|
|
245 |
}
|
| 222 | 246 |
return func(s Statistics) string {
|
| 223 | 247 |
return fmt.Sprintf(format, s.Total-s.Current)
|
| 224 | 248 |
}
|