github.com/kunnos/engine@v1.13.1/pkg/term/term_unix.go (about) 1 // +build !solaris,!windows 2 3 package term 4 5 import ( 6 "syscall" 7 "unsafe" 8 ) 9 10 // GetWinsize returns the window size based on the specified file descriptor. 11 func GetWinsize(fd uintptr) (*Winsize, error) { 12 ws := &Winsize{} 13 _, _, err := syscall.Syscall(syscall.SYS_IOCTL, fd, uintptr(syscall.TIOCGWINSZ), uintptr(unsafe.Pointer(ws))) 14 // Skipp errno = 0 15 if err == 0 { 16 return ws, nil 17 } 18 return ws, err 19 } 20 21 // SetWinsize tries to set the specified window size for the specified file descriptor. 22 func SetWinsize(fd uintptr, ws *Winsize) error { 23 _, _, err := syscall.Syscall(syscall.SYS_IOCTL, fd, uintptr(syscall.TIOCSWINSZ), uintptr(unsafe.Pointer(ws))) 24 // Skipp errno = 0 25 if err == 0 { 26 return nil 27 } 28 return err 29 }