github.com/lazyboychen7/engine@v17.12.1-ce-rc2+incompatible/pkg/term/termios_linux.go (about) 1 package term 2 3 import ( 4 "golang.org/x/sys/unix" 5 ) 6 7 const ( 8 getTermios = unix.TCGETS 9 setTermios = unix.TCSETS 10 ) 11 12 // Termios is the Unix API for terminal I/O. 13 type Termios unix.Termios 14 15 // MakeRaw put the terminal connected to the given file descriptor into raw 16 // mode and returns the previous state of the terminal so that it can be 17 // restored. 18 func MakeRaw(fd uintptr) (*State, error) { 19 termios, err := unix.IoctlGetTermios(int(fd), getTermios) 20 if err != nil { 21 return nil, err 22 } 23 24 var oldState State 25 oldState.termios = Termios(*termios) 26 27 termios.Iflag &^= (unix.IGNBRK | unix.BRKINT | unix.PARMRK | unix.ISTRIP | unix.INLCR | unix.IGNCR | unix.ICRNL | unix.IXON) 28 termios.Oflag &^= unix.OPOST 29 termios.Lflag &^= (unix.ECHO | unix.ECHONL | unix.ICANON | unix.ISIG | unix.IEXTEN) 30 termios.Cflag &^= (unix.CSIZE | unix.PARENB) 31 termios.Cflag |= unix.CS8 32 termios.Cc[unix.VMIN] = 1 33 termios.Cc[unix.VTIME] = 0 34 35 if err := unix.IoctlSetTermios(int(fd), setTermios, termios); err != nil { 36 return nil, err 37 } 38 return &oldState, nil 39 }