1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00
moby--moby/pkg/term/termios_linux.go

39 lines
1 KiB
Go
Raw Normal View History

package term
2013-01-28 17:06:46 -08:00
2013-03-22 04:24:03 -07:00
import (
2013-03-25 18:43:25 -07:00
"unsafe"
"golang.org/x/sys/unix"
2013-03-22 04:24:03 -07:00
)
2013-01-28 17:06:46 -08:00
const (
getTermios = unix.TCGETS
setTermios = unix.TCSETS
2013-01-28 17:06:46 -08:00
)
2013-03-22 04:24:03 -07:00
// Termios is the Unix API for terminal I/O.
type Termios unix.Termios
2013-03-22 04:24:03 -07:00
// MakeRaw put the terminal connected to the given file descriptor into raw
// mode and returns the previous state of the terminal so that it can be
// restored.
2013-06-01 15:55:05 -07:00
func MakeRaw(fd uintptr) (*State, error) {
2013-03-25 18:43:25 -07:00
var oldState State
if _, _, err := unix.Syscall(unix.SYS_IOCTL, fd, getTermios, uintptr(unsafe.Pointer(&oldState.termios))); err != 0 {
2013-03-25 18:43:25 -07:00
return nil, err
}
2013-06-01 15:51:45 -07:00
newState := oldState.termios
2013-03-25 18:43:25 -07:00
newState.Iflag &^= (unix.IGNBRK | unix.BRKINT | unix.PARMRK | unix.ISTRIP | unix.INLCR | unix.IGNCR | unix.ICRNL | unix.IXON)
newState.Oflag |= unix.OPOST
newState.Lflag &^= (unix.ECHO | unix.ECHONL | unix.ICANON | unix.ISIG | unix.IEXTEN)
newState.Cflag &^= (unix.CSIZE | unix.PARENB)
newState.Cflag |= unix.CS8
2013-03-25 18:43:25 -07:00
if _, _, err := unix.Syscall(unix.SYS_IOCTL, fd, setTermios, uintptr(unsafe.Pointer(&newState))); err != 0 {
2013-06-01 15:51:45 -07:00
return nil, err
}
return &oldState, nil
2013-03-25 18:43:25 -07:00
}