2018-02-05 16:05:59 -05:00
|
|
|
package term // import "github.com/docker/docker/pkg/term"
|
2013-01-28 17:06:46 -08:00
|
|
|
|
2013-03-22 04:24:03 -07:00
|
|
|
import (
|
2017-05-04 20:52:19 -04:00
|
|
|
"golang.org/x/sys/unix"
|
2013-03-22 04:24:03 -07:00
|
|
|
)
|
2013-01-28 17:06:46 -08:00
|
|
|
|
|
|
|
const (
|
2017-05-04 20:52:19 -04:00
|
|
|
getTermios = unix.TCGETS
|
|
|
|
setTermios = unix.TCSETS
|
2013-01-28 17:06:46 -08:00
|
|
|
)
|
2013-03-22 04:24:03 -07:00
|
|
|
|
2015-07-25 10:35:07 +02:00
|
|
|
// Termios is the Unix API for terminal I/O.
|
2017-05-15 18:42:02 -07:00
|
|
|
type Termios unix.Termios
|
2013-06-01 16:19:50 -07:00
|
|
|
|
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) {
|
2017-07-17 10:36:52 +02:00
|
|
|
termios, err := unix.IoctlGetTermios(int(fd), getTermios)
|
|
|
|
if err != nil {
|
2013-03-25 18:43:25 -07:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2017-07-17 10:36:52 +02:00
|
|
|
var oldState State
|
|
|
|
oldState.termios = Termios(*termios)
|
2013-03-25 18:43:25 -07:00
|
|
|
|
2017-07-17 10:36:52 +02: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
|
2017-08-03 13:18:29 +02:00
|
|
|
termios.Cc[unix.VMIN] = 1
|
|
|
|
termios.Cc[unix.VTIME] = 0
|
2013-03-25 18:43:25 -07:00
|
|
|
|
2017-07-17 10:36:52 +02:00
|
|
|
if err := unix.IoctlSetTermios(int(fd), setTermios, termios); err != nil {
|
2013-06-01 15:51:45 -07:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &oldState, nil
|
2013-03-25 18:43:25 -07:00
|
|
|
}
|