//go:build linux || darwin || freebsd || netbsd || openbsd || dragonfly package main import ( "os" "syscall" "unsafe" ) // termWidth returns the width of the terminal f, and false when f is not a // terminal: TIOCGWINSZ fails on anything else. func termWidth(f *os.File) (int, bool) { var ws struct{ rows, cols, x, y uint16 } _, _, errno := syscall.Syscall(syscall.SYS_IOCTL, f.Fd(), uintptr(syscall.TIOCGWINSZ), uintptr(unsafe.Pointer(&ws))) if errno != 0 { return 0, false } return int(ws.cols), true }