You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
21 lines
518 B
21 lines
518 B
|
1 week ago
|
//go:build linux || darwin || freebsd || netbsd || openbsd || dragonfly
|
||
|
|
|
||
|
|
package main
|
||
|
|
|
||
|
|
import (
|
||
|
|
"os"
|
||
|
|
"syscall"
|
||
|
|
"unsafe"
|
||
|
|
)
|
||
|
|
|
||
|
|
// termWidth returns the width of the terminal f, and false when f is not a
|
||
|
|
// terminal: TIOCGWINSZ fails on anything else.
|
||
|
|
func termWidth(f *os.File) (int, bool) {
|
||
|
|
var ws struct{ rows, cols, x, y uint16 }
|
||
|
|
_, _, errno := syscall.Syscall(syscall.SYS_IOCTL, f.Fd(), uintptr(syscall.TIOCGWINSZ), uintptr(unsafe.Pointer(&ws)))
|
||
|
|
if errno != 0 {
|
||
|
|
return 0, false
|
||
|
|
}
|
||
|
|
return int(ws.cols), true
|
||
|
|
}
|