truncateProgressSize drops the trailing "X.XMB / Y.YMB" size info from the line currently driving maxBeforeStatusWidth — only that line's shrink can reduce overflow. Returns true if any line was modified.
(lines []lineData)
| 481 | // line currently driving maxBeforeStatusWidth — only that line's shrink can |
| 482 | // reduce overflow. Returns true if any line was modified. |
| 483 | func truncateProgressSize(lines []lineData) bool { |
| 484 | maxIdx := -1 |
| 485 | var maxWidth int |
| 486 | for i := range lines { |
| 487 | l := &lines[i] |
| 488 | if l.progressSizeBytes == 0 { |
| 489 | continue |
| 490 | } |
| 491 | w := lenAnsi(l.prefix) + utf8.RuneCountInString(l.taskID) + lenAnsi(l.progress) |
| 492 | if maxIdx < 0 || w > maxWidth { |
| 493 | maxWidth = w |
| 494 | maxIdx = i |
| 495 | } |
| 496 | } |
| 497 | if maxIdx < 0 { |
| 498 | return false |
| 499 | } |
| 500 | l := &lines[maxIdx] |
| 501 | l.progress = l.progress[:len(l.progress)-l.progressSizeBytes] |
| 502 | l.progressSizeBytes = 0 |
| 503 | return true |
| 504 | } |
| 505 | |
| 506 | // truncateDetails tries to truncate the first line's details to reduce overflow. |
| 507 | // Returns true if any truncation was performed. |