Merge pull request #962 from gtardif/fix_panic_terminal_size_debug

Avoid panic in some weird cases (debug in VSCode for example)
This commit is contained in:
Guillaume Tardif 2020-11-26 16:00:20 +01:00 committed by GitHub
commit efdf80ebb8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 1 deletions

View File

@ -150,7 +150,8 @@ func lineText(event Event, terminalWidth, statusPadding int, color bool) string
// is 2-3 lines long and breaks the line formating // is 2-3 lines long and breaks the line formating
maxStatusLen := terminalWidth - textLen - statusPadding - 15 maxStatusLen := terminalWidth - textLen - statusPadding - 15
status := event.StatusText 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] + "..." status = status[:maxStatusLen] + "..."
} }
text := fmt.Sprintf(" %s %s %s%s %s", text := fmt.Sprintf(" %s %s %s%s %s",