2016-04-15 14:28:44 -04:00
|
|
|
// +build !solaris,!windows
|
|
|
|
|
|
|
|
package term
|
|
|
|
|
|
|
|
import (
|
2017-05-04 20:52:19 -04:00
|
|
|
"golang.org/x/sys/unix"
|
2016-04-15 14:28:44 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
// GetWinsize returns the window size based on the specified file descriptor.
|
|
|
|
func GetWinsize(fd uintptr) (*Winsize, error) {
|
2017-09-01 08:43:09 -04:00
|
|
|
uws, err := unix.IoctlGetWinsize(int(fd), unix.TIOCGWINSZ)
|
|
|
|
ws := &Winsize{Height: uws.Row, Width: uws.Col, x: uws.Xpixel, y: uws.Ypixel}
|
2016-04-15 14:28:44 -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-01 08:43:09 -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)
|
2016-04-15 14:28:44 -04:00
|
|
|
}
|