computeOverflow calculates how many characters the widest line exceeds the terminal width. Returns 0 or negative if all lines fit.
(lines []lineData, maxBeforeStatus, maxStatusLen, timerLen, terminalWidth int)
| 460 | // computeOverflow calculates how many characters the widest line exceeds the terminal width. |
| 461 | // Returns 0 or negative if all lines fit. |
| 462 | func computeOverflow(lines []lineData, maxBeforeStatus, maxStatusLen, timerLen, terminalWidth int) int { |
| 463 | var maxOverflow int |
| 464 | for i := range lines { |
| 465 | l := &lines[i] |
| 466 | detailsLen := len(l.details) |
| 467 | if detailsLen > 0 { |
| 468 | detailsLen++ // space before details |
| 469 | } |
| 470 | // Line width: maxBeforeStatus + space(1) + status + details + minTimerPad(1) + timer |
| 471 | lineWidth := maxBeforeStatus + 1 + maxStatusLen + detailsLen + 1 + timerLen |
| 472 | overflow := lineWidth - terminalWidth |
| 473 | if overflow > maxOverflow { |
| 474 | maxOverflow = overflow |
| 475 | } |
| 476 | } |
| 477 | return maxOverflow |
| 478 | } |
| 479 | |
| 480 | // truncateProgressSize drops the trailing "X.XMB / Y.YMB" size info from the |
| 481 | // line currently driving maxBeforeStatusWidth — only that line's shrink can |