truncateLongestTaskID truncates the longest taskID to reduce overflow. Returns true if truncation was performed. Lengths and slicing are in runes to avoid emitting invalid UTF-8 when taskID contains multi-byte chars.
(lines []lineData, overflow, minIDLen int)
| 524 | // Returns true if truncation was performed. Lengths and slicing are in runes |
| 525 | // to avoid emitting invalid UTF-8 when taskID contains multi-byte chars. |
| 526 | func truncateLongestTaskID(lines []lineData, overflow, minIDLen int) bool { |
| 527 | longestIdx := -1 |
| 528 | longestLen := minIDLen |
| 529 | for i := range lines { |
| 530 | if utf8.RuneCountInString(lines[i].taskID) > longestLen { |
| 531 | longestLen = utf8.RuneCountInString(lines[i].taskID) |
| 532 | longestIdx = i |
| 533 | } |
| 534 | } |
| 535 | |
| 536 | if longestIdx < 0 { |
| 537 | return false |
| 538 | } |
| 539 | |
| 540 | l := &lines[longestIdx] |
| 541 | reduction := overflow + 3 // account for "..." |
| 542 | newLen := max(longestLen-reduction, minIDLen-3) |
| 543 | runes := []rune(l.taskID) |
| 544 | l.taskID = string(runes[:newLen]) + "..." |
| 545 | return true |
| 546 | } |
| 547 | |
| 548 | func (w *ttyWriter) prepareLineData(t *task) lineData { |
| 549 | endTime := time.Now() |
no outgoing calls