From f997d7a1288cba9b49afe3338cdf4662c2bd8dcb Mon Sep 17 00:00:00 2001 From: Guillaume Tardif Date: Wed, 25 Nov 2020 18:07:22 +0100 Subject: [PATCH] Avoid panic in some weird cases (debug in VSCode for example) Signed-off-by: Guillaume Tardif --- progress/tty.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/progress/tty.go b/progress/tty.go index 9a9d70e1b..79e252478 100644 --- a/progress/tty.go +++ b/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",