2015-09-27 06:41:05 +03:00
|
|
|
// +build darwin dragonfly freebsd linux,!appengine netbsd openbsd
|
|
|
|
|
|
|
|
package readline
|
|
|
|
|
|
|
|
import (
|
|
|
|
"syscall"
|
|
|
|
"unsafe"
|
|
|
|
)
|
|
|
|
|
|
|
|
type winsize struct {
|
|
|
|
Row uint16
|
|
|
|
Col uint16
|
|
|
|
Xpixel uint16
|
|
|
|
Ypixel uint16
|
|
|
|
}
|
|
|
|
|
|
|
|
// get width of the terminal
|
|
|
|
func getWidth() int {
|
|
|
|
ws := &winsize{}
|
|
|
|
retCode, _, errno := syscall.Syscall(syscall.SYS_IOCTL,
|
2016-02-17 09:08:55 +03:00
|
|
|
uintptr(StdoutFd),
|
2015-09-27 06:41:05 +03:00
|
|
|
uintptr(syscall.TIOCGWINSZ),
|
|
|
|
uintptr(unsafe.Pointer(ws)))
|
|
|
|
|
|
|
|
if int(retCode) == -1 {
|
|
|
|
panic(errno)
|
|
|
|
}
|
|
|
|
return int(ws.Col)
|
|
|
|
}
|