Skip to content

Commit e587e95

Browse files
authored
Merge pull request #1 from niten94/ioctl-x-sys
Replace `Syscall` with `x/sys/unix.IoctlSetWinsize`
2 parents ffd0fc5 + 28b1785 commit e587e95

File tree

6 files changed

+16
-35
lines changed

6 files changed

+16
-35
lines changed

go.mod

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,7 @@ module github.com/micro-editor/terminal
22

33
go 1.19
44

5-
require github.com/creack/pty v1.1.18
5+
require (
6+
github.com/creack/pty v1.1.18
7+
golang.org/x/sys v0.28.0
8+
)

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
github.com/creack/pty v1.1.18 h1:n56/Zwd5o6whRC5PMGretI4IdRLlmBXYNjScPaBgsbY=
22
github.com/creack/pty v1.1.18/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4=
3+
golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
4+
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=

ioctl_other.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,7 @@
1-
// +build plan9 nacl windows
1+
//go:build plan9 || nacl || windows
22

33
package terminal
44

5-
import (
6-
"os"
7-
)
8-
9-
func ioctl(f *os.File, cmd, p uintptr) error {
10-
return nil
11-
}
12-
135
func (t *VT) ptyResize() error {
146
return nil
157
}

ioctl_posix.go

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,20 @@
1-
// +build linux darwin dragonfly solaris openbsd netbsd freebsd
1+
//go:build linux || darwin || dragonfly || solaris || openbsd || netbsd || freebsd
22

33
package terminal
44

55
import (
6-
"os"
7-
"syscall"
8-
"unsafe"
6+
"golang.org/x/sys/unix"
97
)
108

11-
func ioctl(f *os.File, cmd, p uintptr) error {
12-
_, _, errno := syscall.Syscall(
13-
syscall.SYS_IOCTL,
14-
f.Fd(),
15-
syscall.TIOCSWINSZ,
16-
p)
17-
if errno != 0 {
18-
return syscall.Errno(errno)
19-
}
20-
return nil
21-
}
22-
239
func (t *VT) ptyResize() error {
2410
if t.pty == nil {
2511
return nil
2612
}
27-
var w struct{ row, col, xpix, ypix uint16 }
28-
w.row = uint16(t.dest.rows)
29-
w.col = uint16(t.dest.cols)
30-
w.xpix = 16 * uint16(t.dest.cols)
31-
w.ypix = 16 * uint16(t.dest.rows)
32-
return ioctl(t.pty, syscall.TIOCSWINSZ,
33-
uintptr(unsafe.Pointer(&w)))
13+
w := &unix.Winsize{
14+
Row: uint16(t.dest.rows),
15+
Col: uint16(t.dest.cols),
16+
Xpixel: 16 * uint16(t.dest.cols),
17+
Ypixel: 16 * uint16(t.dest.rows),
18+
}
19+
return unix.IoctlSetWinsize(int(t.pty.Fd()), unix.TIOCSWINSZ, w)
3420
}

vt_other.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//go:build plan9 || nacl || windows
2-
// +build plan9 nacl windows
32

43
package terminal
54

vt_posix.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//go:build linux || darwin || dragonfly || solaris || openbsd || netbsd || freebsd
2-
// +build linux darwin dragonfly solaris openbsd netbsd freebsd
32

43
package terminal
54

0 commit comments

Comments
 (0)