From 23bb9fdbd6b8ade7b8d7424c4cfc1811a3357ea2 Mon Sep 17 00:00:00 2001 From: bytedream Date: Sat, 26 Mar 2022 18:03:46 +0100 Subject: [PATCH] Fix terminal width calculating causing error on some systems --- cmd/crunchyroll-go/cmd/utils.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/cmd/crunchyroll-go/cmd/utils.go b/cmd/crunchyroll-go/cmd/utils.go index bf70564..f76a2bd 100644 --- a/cmd/crunchyroll-go/cmd/utils.go +++ b/cmd/crunchyroll-go/cmd/utils.go @@ -164,7 +164,13 @@ func terminalWidth() int { if err != nil { return 60 } - width, err := strconv.Atoi(strings.Split(strings.ReplaceAll(string(res), "\n", ""), " ")[1]) + // on alpine linux the command `stty size` does not respond the terminal size + // but something like "stty: standard input". this may also apply to other systems + splitOutput := strings.SplitN(strings.ReplaceAll(string(res), "\n", ""), " ", 2) + if len(splitOutput) == 1 { + return 60 + } + width, err := strconv.Atoi(splitOutput[1]) if err != nil { return 60 }