Simplify LightRenderer.Size()

This commit is contained in:
Junegunn Choi 2023-10-23 23:40:56 +09:00
parent b1a0ab8086
commit bac385b59c
No known key found for this signature in database
GPG Key ID: 254BC280FEF9C627

View File

@ -8,9 +8,9 @@ import (
"os/exec"
"strings"
"syscall"
"unsafe"
"github.com/junegunn/fzf/src/util"
"golang.org/x/sys/unix"
"golang.org/x/term"
)
@ -110,18 +110,10 @@ func (r *LightRenderer) getch(nonblock bool) (int, bool) {
return int(b[0]), true
}
type window struct {
lines uint16
columns uint16
width uint16
height uint16
}
func (r *LightRenderer) Size() (termSize, error) {
w := new(window)
_, _, err := syscall.Syscall(syscall.SYS_IOCTL, r.ttyin.Fd(), syscall.TIOCGWINSZ, uintptr(unsafe.Pointer(w)))
if err != 0 {
ws, err := unix.IoctlGetWinsize(int(r.ttyin.Fd()), unix.TIOCGWINSZ)
if err != nil {
return termSize{}, err
}
return termSize{int(w.lines), int(w.columns), int(w.width), int(w.height)}, nil
return termSize{int(ws.Row), int(ws.Col), int(ws.Xpixel), int(ws.Ypixel)}, nil
}