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

40 lines
1.1 KiB
Go
Raw Normal View History

package term // import "github.com/docker/docker/pkg/term"
2013-01-28 20:06:46 -05:00
2013-03-22 07:24:03 -04:00
import (
"golang.org/x/sys/unix"
2013-03-22 07:24:03 -04:00
)
2013-01-28 20:06:46 -05:00
const (
getTermios = unix.TCGETS
setTermios = unix.TCSETS
2013-01-28 20:06:46 -05:00
)
2013-03-22 07:24:03 -04:00
// Termios is the Unix API for terminal I/O.
type Termios unix.Termios
2013-03-22 07:24:03 -04: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 18:55:05 -04:00
func MakeRaw(fd uintptr) (*State, error) {
termios, err := unix.IoctlGetTermios(int(fd), getTermios)
if err != nil {
2013-03-25 21:43:25 -04:00
return nil, err
}
var oldState State
oldState.termios = Termios(*termios)
2013-03-25 21:43:25 -04:00
termios.Iflag &^= (unix.IGNBRK | unix.BRKINT | unix.PARMRK | unix.ISTRIP | unix.INLCR | unix.IGNCR | unix.ICRNL | unix.IXON)
termios.Oflag &^= unix.OPOST
termios.Lflag &^= (unix.ECHO | unix.ECHONL | unix.ICANON | unix.ISIG | unix.IEXTEN)
termios.Cflag &^= (unix.CSIZE | unix.PARENB)
termios.Cflag |= unix.CS8
termios.Cc[unix.VMIN] = 1
termios.Cc[unix.VTIME] = 0
2013-03-25 21:43:25 -04:00
if err := unix.IoctlSetTermios(int(fd), setTermios, termios); err != nil {
2013-06-01 18:51:45 -04:00
return nil, err
}
return &oldState, nil
2013-03-25 21:43:25 -04:00
}