blob: 7cccf255988ed0a0429bec8be375247d918a662a (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
//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
}
|