-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathpty_unix.go
43 lines (38 loc) · 951 Bytes
/
pty_unix.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//go:build darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris
// +build darwin dragonfly freebsd linux netbsd openbsd solaris
package xpty
import (
"github.com/charmbracelet/x/termios"
"golang.org/x/sys/unix"
)
// setWinsize sets window size for the PTY.
func (p *UnixPty) setWinsize(width, height, x, y int) error {
var rErr error
if err := p.Control(func(fd uintptr) {
rErr = termios.SetWinsize(int(fd), &unix.Winsize{
Row: uint16(height),
Col: uint16(width),
Xpixel: uint16(x),
Ypixel: uint16(y),
})
}); err != nil {
rErr = err
}
return rErr
}
// size returns the size of the PTY.
func (p *UnixPty) size() (width, height int, err error) {
var rErr error
if err := p.Control(func(fd uintptr) {
ws, err := termios.GetWinsize(int(fd))
if err != nil {
rErr = err
return
}
width = int(ws.Col)
height = int(ws.Row)
}); err != nil {
rErr = err
}
return width, height, rErr
}