minor: PercentageRound width uint
Vladimir Bauer
1 year, 10 months ago
| 232 | 232 |
var tip component
|
| 233 | 233 |
var refilling, filling, padding []byte
|
| 234 | 234 |
var fillCount int
|
| 235 | |
curWidth := int(internal.PercentageRound(stat.Total, stat.Current, int64(width)))
|
|
235 |
curWidth := int(internal.PercentageRound(stat.Total, stat.Current, uint(width)))
|
| 236 | 236 |
|
| 237 | 237 |
if curWidth != 0 {
|
| 238 | 238 |
if !stat.Completed || s.tipOnComplete {
|
|
| 242 | 242 |
}
|
| 243 | 243 |
switch refWidth := 0; {
|
| 244 | 244 |
case stat.Refill != 0:
|
| 245 | |
refWidth = int(internal.PercentageRound(stat.Total, stat.Refill, int64(width)))
|
|
245 |
refWidth = int(internal.PercentageRound(stat.Total, stat.Refill, uint(width)))
|
| 246 | 246 |
curWidth -= refWidth
|
| 247 | 247 |
refWidth += curWidth
|
| 248 | 248 |
fallthrough
|
| 13 | 13 |
}
|
| 14 | 14 |
|
| 15 | 15 |
// PercentageRound same as Percentage but with math.Round.
|
| 16 | |
func PercentageRound(total, current, width int64) float64 {
|
| 17 | |
if total < 0 || current < 0 || width < 0 {
|
|
16 |
func PercentageRound(total, current int64, width uint) float64 {
|
|
17 |
if total < 0 || current < 0 {
|
| 18 | 18 |
return 0
|
| 19 | 19 |
}
|
| 20 | |
return math.Round(Percentage(uint(total), uint(current), uint(width)))
|
|
20 |
return math.Round(Percentage(uint(total), uint(current), width))
|
| 21 | 21 |
}
|
| 3 | 3 |
|
| 4 | 4 |
func TestPercentage(t *testing.T) {
|
| 5 | 5 |
// key is barWidth
|
| 6 | |
testSuite := map[int64][]struct {
|
|
6 |
testSuite := map[uint][]struct {
|
| 7 | 7 |
name string
|
| 8 | 8 |
total int64
|
| 9 | 9 |
current int64
|