default decorator's formats
Vladimir Bauer
6 years ago
| 44 | 44 |
wc = widthConf
|
| 45 | 45 |
}
|
| 46 | 46 |
wc.Init()
|
|
47 |
if pairFmt == "" {
|
|
48 |
pairFmt = "%d / %d"
|
|
49 |
}
|
| 47 | 50 |
d := &countersDecorator{
|
| 48 | 51 |
WC: wc,
|
| 49 | 52 |
unit: unit,
|
| 24 | 24 |
}
|
| 25 | 25 |
}
|
| 26 | 26 |
|
| 27 | |
res := strconv.FormatFloat(float64(s), 'f', prec, 64)
|
|
27 |
var b strings.Builder
|
|
28 |
b.WriteString(strconv.FormatFloat(float64(s), 'f', prec, 64))
|
| 28 | 29 |
|
| 29 | 30 |
if st.Flag(' ') {
|
| 30 | |
res += " "
|
|
31 |
b.WriteString(" ")
|
| 31 | 32 |
}
|
| 32 | |
res += "%"
|
|
33 |
b.WriteString("%")
|
| 33 | 34 |
|
| 34 | 35 |
if w, ok := st.Width(); ok {
|
| 35 | |
if len(res) < w {
|
| 36 | |
pad := strings.Repeat(" ", w-len(res))
|
|
36 |
if l := b.Len(); l < w {
|
|
37 |
pad := strings.Repeat(" ", w-l)
|
| 37 | 38 |
if st.Flag('-') {
|
| 38 | |
res += pad
|
|
39 |
b.WriteString(pad)
|
| 39 | 40 |
} else {
|
| 40 | |
res = pad + res
|
|
41 |
tmp := b.String()
|
|
42 |
b.Reset()
|
|
43 |
b.WriteString(pad)
|
|
44 |
b.WriteString(tmp)
|
| 41 | 45 |
}
|
| 42 | 46 |
}
|
| 43 | 47 |
}
|
| 44 | 48 |
|
| 45 | |
io.WriteString(st, res)
|
|
49 |
io.WriteString(st, b.String())
|
| 46 | 50 |
}
|
| 47 | 51 |
|
| 48 | 52 |
// Percentage returns percentage decorator. It's a wrapper of NewPercentage.
|
|
| 65 | 69 |
wc = widthConf
|
| 66 | 70 |
}
|
| 67 | 71 |
wc.Init()
|
|
72 |
if fmt == "" {
|
|
73 |
fmt = "% d"
|
|
74 |
}
|
| 68 | 75 |
d := &percentageDecorator{
|
| 69 | 76 |
WC: wc,
|
| 70 | 77 |
fmt: fmt,
|
| 14 | 14 |
expected string
|
| 15 | 15 |
}{
|
| 16 | 16 |
{
|
|
17 |
name: "empty fmt",
|
|
18 |
unit: UnitKiB,
|
|
19 |
fmt: "",
|
|
20 |
current: 0,
|
|
21 |
elapsed: time.Second,
|
|
22 |
expected: "0b/s",
|
|
23 |
},
|
|
24 |
{
|
| 17 | 25 |
name: "UnitKiB:%d:0b",
|
| 18 | 26 |
unit: UnitKiB,
|
| 19 | 27 |
fmt: "%d",
|
|
| 134 | 142 |
expected string
|
| 135 | 143 |
}{
|
| 136 | 144 |
{
|
|
145 |
name: "empty fmt",
|
|
146 |
unit: UnitKB,
|
|
147 |
fmt: "",
|
|
148 |
current: 0,
|
|
149 |
elapsed: time.Second,
|
|
150 |
expected: "0b/s",
|
|
151 |
},
|
|
152 |
{
|
| 137 | 153 |
name: "UnitKB:%d:0b",
|
| 138 | 154 |
unit: UnitKB,
|
| 139 | 155 |
fmt: "%d",
|