github.com/endophage/docker@v1.4.2-0.20161027011718-242853499895/pkg/term/termios_linux.go (about) 1 // +build !cgo 2 3 package term 4 5 import ( 6 "syscall" 7 "unsafe" 8 ) 9 10 const ( 11 getTermios = syscall.TCGETS 12 setTermios = syscall.TCSETS 13 ) 14 15 // Termios is the Unix API for terminal I/O. 16 type Termios struct { 17 Iflag uint32 18 Oflag uint32 19 Cflag uint32 20 Lflag uint32 21 Cc [20]byte 22 Ispeed uint32 23 Ospeed uint32 24 } 25 26 // MakeRaw put the terminal connected to the given file descriptor into raw 27 // mode and returns the previous state of the terminal so that it can be 28 // restored. 29 func MakeRaw(fd uintptr) (*State, error) { 30 var oldState State 31 if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, fd, getTermios, uintptr(unsafe.Pointer(&oldState.termios))); err != 0 { 32 return nil, err 33 } 34 35 newState := oldState.termios 36 37 newState.Iflag &^= (syscall.IGNBRK | syscall.BRKINT | syscall.PARMRK | syscall.ISTRIP | syscall.INLCR | syscall.IGNCR | syscall.ICRNL | syscall.IXON) 38 newState.Oflag &^= syscall.OPOST 39 newState.Lflag &^= (syscall.ECHO | syscall.ECHONL | syscall.ICANON | syscall.ISIG | syscall.IEXTEN) 40 newState.Cflag &^= (syscall.CSIZE | syscall.PARENB) 41 newState.Cflag |= syscall.CS8 42 43 if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, fd, setTermios, uintptr(unsafe.Pointer(&newState))); err != 0 { 44 return nil, err 45 } 46 return &oldState, nil 47 }