()
| 8 | ) |
| 9 | |
| 10 | func terminalWidth() uint { |
| 11 | const ( |
| 12 | maxWidth = 140 // don't go over 140 chars anyway |
| 13 | defaultWidth = 110 // in case we can't get the terminal width |
| 14 | ) |
| 15 | |
| 16 | var w uint |
| 17 | |
| 18 | defer func() { |
| 19 | if err := recover(); err != nil { |
| 20 | w = defaultWidth |
| 21 | } |
| 22 | }() |
| 23 | |
| 24 | ws := &struct{ Row, Col, Xpixel, Ypixel uint16 }{} |
| 25 | |
| 26 | retCode, _, errno := syscall.Syscall(syscall.SYS_IOCTL, |
| 27 | uintptr(syscall.Stdout), |
| 28 | uintptr(syscall.TIOCGWINSZ), |
| 29 | uintptr(unsafe.Pointer(ws))) |
| 30 | |
| 31 | if int(retCode) == -1 { |
| 32 | panic(errno) |
| 33 | } |
| 34 | |
| 35 | if ws.Col > maxWidth { |
| 36 | return maxWidth |
| 37 | } |
| 38 | |
| 39 | w = uint(ws.Col) |
| 40 | return w |
| 41 | } |
no outgoing calls
no test coverage detected