makeProgressBar creates a visual progress bar percent should be between 0 and 100 width is the number of characters for the bar
(percent float64, width int)
| 359 | // percent should be between 0 and 100 |
| 360 | // width is the number of characters for the bar |
| 361 | func makeProgressBar(percent float64, width int) string { |
| 362 | if percent < 0 { |
| 363 | percent = 0 |
| 364 | } |
| 365 | if percent > 100 { |
| 366 | percent = 100 |
| 367 | } |
| 368 | |
| 369 | filled := int(float64(width) * percent / 100.0) |
| 370 | empty := width - filled |
| 371 | |
| 372 | bar := "[" |
| 373 | for i := 0; i < filled; i++ { |
| 374 | bar += "█" |
| 375 | } |
| 376 | for i := 0; i < empty; i++ { |
| 377 | bar += "░" |
| 378 | } |
| 379 | bar += fmt.Sprintf("] %.1f%%", percent) |
| 380 | |
| 381 | return bar |
| 382 | } |
no outgoing calls
no test coverage detected