소스 검색

Avoid panic in some weird cases (debug in VSCode for example)

Signed-off-by: Guillaume Tardif <[email protected]>
Guillaume Tardif 5 년 전
부모
커밋
f997d7a128
1개의 변경된 파일2개의 추가작업 그리고 1개의 파일을 삭제
  1. 2 1
      progress/tty.go

+ 2 - 1
progress/tty.go

@@ -150,7 +150,8 @@ func lineText(event Event, terminalWidth, statusPadding int, color bool) string
 	// is 2-3 lines long and breaks the line formating
 	maxStatusLen := terminalWidth - textLen - statusPadding - 15
 	status := event.StatusText
-	if len(status) > maxStatusLen {
+	// in some cases (debugging under VS Code), terminalWidth is set to zero by goterm.Width() ; ensuring we don't tweak strings with negative char index
+	if maxStatusLen > 0 && len(status) > maxStatusLen {
 		status = status[:maxStatusLen] + "..."
 	}
 	text := fmt.Sprintf(" %s %s %s%s %s",