github.com/ActiveState/cli@v0.0.0-20240508170324-6801f60cd051/internal/termutils/termutils.go (about) 1 package termutils 2 3 import ( 4 "os" 5 6 "golang.org/x/term" 7 8 "github.com/ActiveState/cli/internal/logging" 9 ) 10 11 const fallbackWidth = 100 12 const maxWidth = 160 13 14 func GetWidth() int { 15 termWidth, _, err := term.GetSize(int(os.Stdout.Fd())) 16 if err != nil { 17 logging.Debug("Cannot get terminal size: %v", err) 18 termWidth = fallbackWidth 19 } 20 if termWidth == 0 { 21 termWidth = fallbackWidth 22 } 23 if termWidth > maxWidth { 24 termWidth = maxWidth 25 } 26 return termWidth 27 }