From bac385b59ccef279400689d406bf270cfdee06f3 Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Mon, 23 Oct 2023 23:40:56 +0900 Subject: [PATCH] Simplify LightRenderer.Size() --- src/tui/light_unix.go | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/tui/light_unix.go b/src/tui/light_unix.go index b9e433cc..4ca847b4 100644 --- a/src/tui/light_unix.go +++ b/src/tui/light_unix.go @@ -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 }