github.com/jiasir/docker@v1.3.3-0.20170609024000-252e610103e7/pkg/term/winsize.go (about) 1 // +build !solaris,!windows 2 3 package term 4 5 import ( 6 "unsafe" 7 8 "golang.org/x/sys/unix" 9 ) 10 11 // GetWinsize returns the window size based on the specified file descriptor. 12 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 } 19 return ws, err 20 } 21 22 // SetWinsize tries to set the specified window size for the specified file descriptor. 23 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 30 }