//go:build linux || darwin || freebsd || netbsd || openbsd package main import ( "os" "syscall" "unsafe" ) // termCols asks the terminal for its width. // // This is an ioctl rather than golang.org/x/term because the spec keeps this // binary free of third-party modules; it is a dozen lines and only needs to // work on the platforms prognosis is built for. func termCols() (int, bool) { var ws struct{ Row, Col, Xpixel, Ypixel uint16 } _, _, errno := syscall.Syscall( syscall.SYS_IOCTL, os.Stdout.Fd(), uintptr(syscall.TIOCGWINSZ), uintptr(unsafe.Pointer(&ws)), ) if errno != 0 || ws.Col == 0 { return 0, false } return int(ws.Col), true }