Use unix.IoctlGetWinsize and unix.IoctlSetWinsize instead of manually
reimplementing them.
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
| ... | ... |
@@ -3,28 +3,18 @@ |
| 3 | 3 |
package term |
| 4 | 4 |
|
| 5 | 5 |
import ( |
| 6 |
- "unsafe" |
|
| 7 |
- |
|
| 8 | 6 |
"golang.org/x/sys/unix" |
| 9 | 7 |
) |
| 10 | 8 |
|
| 11 | 9 |
// GetWinsize returns the window size based on the specified file descriptor. |
| 12 | 10 |
func GetWinsize(fd uintptr) (*Winsize, error) {
|
| 13 |
- ws := &Winsize{}
|
|
| 14 |
- _, _, err := unix.Syscall(unix.SYS_IOCTL, fd, uintptr(unix.TIOCGWINSZ), uintptr(unsafe.Pointer(ws))) |
|
| 15 |
- // Skipp errno = 0 |
|
| 16 |
- if err == 0 {
|
|
| 17 |
- return ws, nil |
|
| 18 |
- } |
|
| 11 |
+ uws, err := unix.IoctlGetWinsize(int(fd), unix.TIOCGWINSZ) |
|
| 12 |
+ ws := &Winsize{Height: uws.Row, Width: uws.Col, x: uws.Xpixel, y: uws.Ypixel}
|
|
| 19 | 13 |
return ws, err |
| 20 | 14 |
} |
| 21 | 15 |
|
| 22 | 16 |
// SetWinsize tries to set the specified window size for the specified file descriptor. |
| 23 | 17 |
func SetWinsize(fd uintptr, ws *Winsize) error {
|
| 24 |
- _, _, err := unix.Syscall(unix.SYS_IOCTL, fd, uintptr(unix.TIOCSWINSZ), uintptr(unsafe.Pointer(ws))) |
|
| 25 |
- // Skipp errno = 0 |
|
| 26 |
- if err == 0 {
|
|
| 27 |
- return nil |
|
| 28 |
- } |
|
| 29 |
- return err |
|
| 18 |
+ uws := &unix.Winsize{Row: ws.Height, Col: ws.Width, Xpixel: ws.x, Ypixel: ws.y}
|
|
| 19 |
+ return unix.IoctlSetWinsize(int(fd), unix.TIOCSWINSZ, uws) |
|
| 30 | 20 |
} |