mark2web/vendor/github.com/gosuri/uilive/terminal_size.go
Sebastian Frank a781485c0a
Some checks failed
continuous-integration/drone/push Build is failing
no git submodules
2022-02-28 10:28:34 +01:00

38 lines
606 B
Go

// +build !windows
package uilive
import (
"os"
"runtime"
"syscall"
"unsafe"
)
type windowSize struct {
rows uint16
cols uint16
}
var out *os.File
var err error
var sz windowSize
func getTermSize() (int, int) {
if runtime.GOOS == "openbsd" {
out, err = os.OpenFile("/dev/tty", os.O_RDWR, 0)
if err != nil {
return 0, 0
}
} else {
out, err = os.OpenFile("/dev/tty", os.O_WRONLY, 0)
if err != nil {
return 0, 0
}
}
_, _, _ = syscall.Syscall(syscall.SYS_IOCTL,
out.Fd(), uintptr(syscall.TIOCGWINSZ), uintptr(unsafe.Pointer(&sz)))
return int(sz.cols), int(sz.rows)
}