Fix terminal width calculating causing error on some systems

This commit is contained in:
bytedream 2022-03-26 18:03:46 +01:00
parent 449cc37896
commit 23bb9fdbd6

View file

@ -164,7 +164,13 @@ func terminalWidth() int {
if err != nil { if err != nil {
return 60 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 { if err != nil {
return 60 return 60
} }