From d8e58b2fab869af7f6dfff68706ae6b54da770e6 Mon Sep 17 00:00:00 2001 From: niten94 <127052329+niten94@users.noreply.github.com> Date: Mon, 23 Dec 2024 13:45:32 +0800 Subject: [PATCH 1/3] Remove unused ioctl function in ioctl_other.go --- ioctl_other.go | 8 -------- 1 file changed, 8 deletions(-) diff --git a/ioctl_other.go b/ioctl_other.go index c08989b..c01bae5 100644 --- a/ioctl_other.go +++ b/ioctl_other.go @@ -2,14 +2,6 @@ package terminal -import ( - "os" -) - -func ioctl(f *os.File, cmd, p uintptr) error { - return nil -} - func (t *VT) ptyResize() error { return nil } From 4be3967f413f3f2e1853a4a0478e46f8b6969783 Mon Sep 17 00:00:00 2001 From: niten94 <127052329+niten94@users.noreply.github.com> Date: Mon, 23 Dec 2024 13:47:52 +0800 Subject: [PATCH 2/3] Remove build constraints with old syntax --- ioctl_other.go | 2 +- ioctl_posix.go | 2 +- vt_other.go | 1 - vt_posix.go | 1 - 4 files changed, 2 insertions(+), 4 deletions(-) diff --git a/ioctl_other.go b/ioctl_other.go index c01bae5..ef6f591 100644 --- a/ioctl_other.go +++ b/ioctl_other.go @@ -1,4 +1,4 @@ -// +build plan9 nacl windows +//go:build plan9 || nacl || windows package terminal diff --git a/ioctl_posix.go b/ioctl_posix.go index beb54eb..d6dda6c 100644 --- a/ioctl_posix.go +++ b/ioctl_posix.go @@ -1,4 +1,4 @@ -// +build linux darwin dragonfly solaris openbsd netbsd freebsd +//go:build linux || darwin || dragonfly || solaris || openbsd || netbsd || freebsd package terminal diff --git a/vt_other.go b/vt_other.go index d16c91e..1ec6377 100644 --- a/vt_other.go +++ b/vt_other.go @@ -1,5 +1,4 @@ //go:build plan9 || nacl || windows -// +build plan9 nacl windows package terminal diff --git a/vt_posix.go b/vt_posix.go index a594eb6..022be99 100644 --- a/vt_posix.go +++ b/vt_posix.go @@ -1,5 +1,4 @@ //go:build linux || darwin || dragonfly || solaris || openbsd || netbsd || freebsd -// +build linux darwin dragonfly solaris openbsd netbsd freebsd package terminal From 28b17857043626ef6fa9262c4c58908bfeab8602 Mon Sep 17 00:00:00 2001 From: niten94 <127052329+niten94@users.noreply.github.com> Date: Mon, 23 Dec 2024 20:42:20 +0800 Subject: [PATCH 3/3] Replace Syscall with x/sys/unix.IoctlSetWinsize --- go.mod | 5 ++++- go.sum | 2 ++ ioctl_posix.go | 30 ++++++++---------------------- 3 files changed, 14 insertions(+), 23 deletions(-) diff --git a/go.mod b/go.mod index d3e2cfc..5bcfd12 100644 --- a/go.mod +++ b/go.mod @@ -2,4 +2,7 @@ module github.com/zyedidia/terminal go 1.19 -require github.com/creack/pty v1.1.18 +require ( + github.com/creack/pty v1.1.18 + golang.org/x/sys v0.28.0 +) diff --git a/go.sum b/go.sum index f32a99d..0e01ece 100644 --- a/go.sum +++ b/go.sum @@ -1,2 +1,4 @@ github.com/creack/pty v1.1.18 h1:n56/Zwd5o6whRC5PMGretI4IdRLlmBXYNjScPaBgsbY= github.com/creack/pty v1.1.18/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4= +golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA= +golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= diff --git a/ioctl_posix.go b/ioctl_posix.go index d6dda6c..6ad6bb8 100644 --- a/ioctl_posix.go +++ b/ioctl_posix.go @@ -3,32 +3,18 @@ package terminal import ( - "os" - "syscall" - "unsafe" + "golang.org/x/sys/unix" ) -func ioctl(f *os.File, cmd, p uintptr) error { - _, _, errno := syscall.Syscall( - syscall.SYS_IOCTL, - f.Fd(), - syscall.TIOCSWINSZ, - p) - if errno != 0 { - return syscall.Errno(errno) - } - return nil -} - func (t *VT) ptyResize() error { if t.pty == nil { return nil } - var w struct{ row, col, xpix, ypix uint16 } - w.row = uint16(t.dest.rows) - w.col = uint16(t.dest.cols) - w.xpix = 16 * uint16(t.dest.cols) - w.ypix = 16 * uint16(t.dest.rows) - return ioctl(t.pty, syscall.TIOCSWINSZ, - uintptr(unsafe.Pointer(&w))) + w := &unix.Winsize{ + Row: uint16(t.dest.rows), + Col: uint16(t.dest.cols), + Xpixel: 16 * uint16(t.dest.cols), + Ypixel: 16 * uint16(t.dest.rows), + } + return unix.IoctlSetWinsize(int(t.pty.Fd()), unix.TIOCSWINSZ, w) }