github.com/lazyboychen7/engine@v17.12.1-ce-rc2+incompatible/pkg/term/winsize.go (about)

     1  // +build !windows
     2  
     3  package term
     4  
     5  import (
     6  	"golang.org/x/sys/unix"
     7  )
     8  
     9  // GetWinsize returns the window size based on the specified file descriptor.
    10  func GetWinsize(fd uintptr) (*Winsize, error) {
    11  	uws, err := unix.IoctlGetWinsize(int(fd), unix.TIOCGWINSZ)
    12  	ws := &Winsize{Height: uws.Row, Width: uws.Col, x: uws.Xpixel, y: uws.Ypixel}
    13  	return ws, err
    14  }
    15  
    16  // SetWinsize tries to set the specified window size for the specified file descriptor.
    17  func SetWinsize(fd uintptr, ws *Winsize) error {
    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)
    20  }