@@ -317,10 +317,7 @@ func (w *ttyWriter) printWithDimensions(terminalWidth, terminalHeight int) {
317317 allTasks := slices .Collect (w .parentTasks ())
318318
319319 // Available lines: terminal height - 2 (header line + potential "more" line)
320- maxLines := terminalHeight - 2
321- if maxLines < 1 {
322- maxLines = 1
323- }
320+ maxLines := max (terminalHeight - 2 , 1 )
324321
325322 showMore := len (allTasks ) > maxLines
326323 tasksToShow := allTasks
@@ -354,10 +351,7 @@ func (w *ttyWriter) printWithDimensions(terminalWidth, terminalHeight int) {
354351 if showMore {
355352 moreCount := len (allTasks ) - len (tasksToShow )
356353 moreText := fmt .Sprintf (" ... %d more" , moreCount )
357- pad := terminalWidth - len (moreText )
358- if pad < 0 {
359- pad = 0
360- }
354+ pad := max (terminalWidth - len (moreText ), 0 )
361355 _ , _ = fmt .Fprintf (w .out , "%s%s\n " , moreText , strings .Repeat (" " , pad ))
362356 numLines ++
363357 }
@@ -392,10 +386,7 @@ func (w *ttyWriter) applyPadding(lines []lineData, terminalWidth int, timerLen i
392386 if l .details != "" {
393387 lineLen += 1 + utf8 .RuneCountInString (l .details )
394388 }
395- l .timerPad = terminalWidth - lineLen - timerLen
396- if l .timerPad < 1 {
397- l .timerPad = 1
398- }
389+ l .timerPad = max (terminalWidth - lineLen - timerLen , 1 )
399390 lines [i ] = l
400391
401392 }
@@ -472,10 +463,7 @@ func truncateDetails(lines []lineData, overflow int) bool {
472463 for i := range lines {
473464 l := & lines [i ]
474465 if len (l .details ) > 3 {
475- reduction := overflow
476- if reduction > len (l .details )- 3 {
477- reduction = len (l .details ) - 3
478- }
466+ reduction := min (overflow , len (l .details )- 3 )
479467 l .details = l .details [:len (l .details )- reduction - 3 ] + "..."
480468 return true
481469 } else if l .details != "" {
@@ -504,10 +492,7 @@ func truncateLongestTaskID(lines []lineData, overflow, minIDLen int) bool {
504492
505493 l := & lines [longestIdx ]
506494 reduction := overflow + 3 // account for "..."
507- newLen := len (l .taskID ) - reduction
508- if newLen < minIDLen - 3 {
509- newLen = minIDLen - 3
510- }
495+ newLen := max (len (l .taskID )- reduction , minIDLen - 3 )
511496 if newLen > 0 {
512497 l .taskID = l .taskID [:newLen ] + "..."
513498 }
@@ -546,10 +531,7 @@ func (w *ttyWriter) prepareLineData(t *task) lineData {
546531 total += child .total
547532 current += child .current
548533 r := len (percentChars ) - 1
549- p := child .percent
550- if p > 100 {
551- p = 100
552- }
534+ p := min (child .percent , 100 )
553535 completion = append (completion , percentChars [r * p / 100 ])
554536 }
555537 }
0 commit comments