use percentage func
Vladimir Bauer
9 years ago
| 72 | 72 | |
| 73 | 73 | func (b *Bar) AppendPercentage() *Bar { |
| 74 | 74 | b.AppendFunc(func(s *Statistics) string { |
| 75 | completed := int(100 * float64(s.Current) / float64(s.Total)) | |
| 75 | completed := percentage(s.Total, s.Current, 100) | |
| 76 | 76 | return fmt.Sprintf("%3d %%", completed) |
| 77 | 77 | }) |
| 78 | 78 | return b |
| 81 | 81 | func (b *Bar) PrependPercentage(padding int) *Bar { |
| 82 | 82 | layout := "%" + strconv.Itoa(padding) + "d %%" |
| 83 | 83 | b.PrependFunc(func(s *Statistics) string { |
| 84 | completed := int(100 * float64(s.Current) / float64(s.Total)) | |
| 84 | completed := percentage(s.Total, s.Current, 100) | |
| 85 | 85 | return fmt.Sprintf(layout, completed) |
| 86 | 86 | }) |
| 87 | 87 | return b |