syscall.SYS_IOCTL is not portable
This commit is contained in:
parent
c8c75cc295
commit
c53d9fe30b
@ -4,9 +4,9 @@ package prompt
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"syscall"
|
"syscall"
|
||||||
"unsafe"
|
|
||||||
|
|
||||||
"github.com/c-bata/go-prompt/internal/term"
|
"github.com/c-bata/go-prompt/internal/term"
|
||||||
|
"golang.org/x/sys/unix"
|
||||||
)
|
)
|
||||||
|
|
||||||
const maxReadBytes = 1024
|
const maxReadBytes = 1024
|
||||||
@ -50,25 +50,11 @@ func (t *PosixParser) Read() ([]byte, error) {
|
|||||||
return buf[:n], nil
|
return buf[:n], nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// winsize is winsize struct got from the ioctl(2) system call.
|
|
||||||
type ioctlWinsize struct {
|
|
||||||
Row uint16
|
|
||||||
Col uint16
|
|
||||||
X uint16 // pixel value
|
|
||||||
Y uint16 // pixel value
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetWinSize returns WinSize object to represent width and height of terminal.
|
// GetWinSize returns WinSize object to represent width and height of terminal.
|
||||||
func (t *PosixParser) GetWinSize() *WinSize {
|
func (t *PosixParser) GetWinSize() *WinSize {
|
||||||
ws := &ioctlWinsize{}
|
ws, err := unix.IoctlGetWinsize(t.fd, unix.TIOCGWINSZ)
|
||||||
retCode, _, errno := syscall.Syscall(
|
if err != nil {
|
||||||
syscall.SYS_IOCTL,
|
panic(err)
|
||||||
uintptr(t.fd),
|
|
||||||
uintptr(syscall.TIOCGWINSZ),
|
|
||||||
uintptr(unsafe.Pointer(ws)))
|
|
||||||
|
|
||||||
if int(retCode) == -1 {
|
|
||||||
panic(errno)
|
|
||||||
}
|
}
|
||||||
return &WinSize{
|
return &WinSize{
|
||||||
Row: ws.Row,
|
Row: ws.Row,
|
||||||
|
Loading…
Reference in New Issue
Block a user