//go:build linux package formatter import ( "syscall" "unsafe" ) type winsize struct { Row, Col uint16 Xpixel, Ypixel uint16 } // getTerminalWidth returns the width of the stdout terminal in columns. // If the output is not a terminal or the width cannot be determined, it returns (0, error). func getTerminalWidth() (int, error) { var ws winsize _, _, errno := syscall.Syscall( syscall.SYS_IOCTL, uintptr(syscall.Stdout), uintptr(syscall.TIOCGWINSZ), uintptr(unsafe.Pointer(&ws)), ) if errno != 0 { return 0, errno } return int(ws.Col), nil }