2022-11-20 15:40:01 -05:00
|
|
|
//go:build !windows
|
2017-11-08 11:34:04 -05:00
|
|
|
// +build !windows
|
2017-04-17 18:08:24 -04:00
|
|
|
|
2020-04-16 05:23:37 -04:00
|
|
|
package term
|
2017-04-17 18:08:24 -04:00
|
|
|
|
|
|
|
import (
|
2017-05-10 18:41:46 -04:00
|
|
|
"golang.org/x/sys/unix"
|
2017-04-17 18:08:24 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
// GetWinsize returns the window size based on the specified file descriptor.
|
|
|
|
func GetWinsize(fd uintptr) (*Winsize, error) {
|
2017-09-08 19:25:37 -04:00
|
|
|
uws, err := unix.IoctlGetWinsize(int(fd), unix.TIOCGWINSZ)
|
|
|
|
ws := &Winsize{Height: uws.Row, Width: uws.Col, x: uws.Xpixel, y: uws.Ypixel}
|
2017-04-17 18:08:24 -04:00
|
|
|
return ws, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetWinsize tries to set the specified window size for the specified file descriptor.
|
|
|
|
func SetWinsize(fd uintptr, ws *Winsize) error {
|
2017-09-08 19:25:37 -04:00
|
|
|
uws := &unix.Winsize{Row: ws.Height, Col: ws.Width, Xpixel: ws.x, Ypixel: ws.y}
|
|
|
|
return unix.IoctlSetWinsize(int(fd), unix.TIOCSWINSZ, uws)
|
2017-04-17 18:08:24 -04:00
|
|
|
}
|