| 1 | //go:build linux || darwin |
| 2 | |
| 3 | package main |
| 4 | |
| 5 | import ( |
| 6 | "os" |
| 7 | "syscall" |
| 8 | "unsafe" |
| 9 | ) |
| 10 | |
| 11 | // windowColumns asks the terminal f is open on how many columns wide it |
| 12 | // is. It reports false when f is no terminal. |
| 13 | func windowColumns(f *os.File) (int, bool) { |
| 14 | var ws struct{ rows, cols, xpixels, ypixels uint16 } |
| 15 | _, _, errno := syscall.Syscall(syscall.SYS_IOCTL, f.Fd(), uintptr(syscall.TIOCGWINSZ), uintptr(unsafe.Pointer(&ws))) |
| 16 | return int(ws.cols), errno == 0 |
| 17 | } |