| 413 | } |
| 414 | |
| 415 | func (w *ttyWriter) adjustLineWidth(lines []lineData, timerLen int, terminalWidth int) { |
| 416 | const minIDLen = 10 |
| 417 | maxStatusLen := maxStatusLength(lines) |
| 418 | |
| 419 | // Iteratively truncate until all lines fit |
| 420 | for range 100 { // safety limit |
| 421 | maxBeforeStatus := maxBeforeStatusWidth(lines) |
| 422 | overflow := computeOverflow(lines, maxBeforeStatus, maxStatusLen, timerLen, terminalWidth) |
| 423 | |
| 424 | if overflow <= 0 { |
| 425 | break |
| 426 | } |
| 427 | |
| 428 | // Drop ancillary content (details, progress size info) before touching the taskID. |
| 429 | if !truncateDetails(lines, overflow) && !truncateProgressSize(lines) && !truncateLongestTaskID(lines, overflow, minIDLen) { |
| 430 | break // Can't truncate further |
| 431 | } |
| 432 | } |
| 433 | } |
| 434 | |
| 435 | // maxStatusLength returns the maximum status text length across all lines. |
| 436 | func maxStatusLength(lines []lineData) int { |