github.com/rentongzhang/docker@v1.8.2-rc1/pkg/term/termios_freebsd.go (about)

     1  package term
     2  
     3  import (
     4  	"syscall"
     5  	"unsafe"
     6  )
     7  
     8  const (
     9  	getTermios = syscall.TIOCGETA
    10  	setTermios = syscall.TIOCSETA
    11  
    12  	IGNBRK = syscall.IGNBRK
    13  	PARMRK = syscall.PARMRK
    14  	INLCR  = syscall.INLCR
    15  	IGNCR  = syscall.IGNCR
    16  	ECHONL = syscall.ECHONL
    17  	CSIZE  = syscall.CSIZE
    18  	ICRNL  = syscall.ICRNL
    19  	ISTRIP = syscall.ISTRIP
    20  	PARENB = syscall.PARENB
    21  	ECHO   = syscall.ECHO
    22  	ICANON = syscall.ICANON
    23  	ISIG   = syscall.ISIG
    24  	IXON   = syscall.IXON
    25  	BRKINT = syscall.BRKINT
    26  	INPCK  = syscall.INPCK
    27  	OPOST  = syscall.OPOST
    28  	CS8    = syscall.CS8
    29  	IEXTEN = syscall.IEXTEN
    30  )
    31  
    32  type Termios struct {
    33  	Iflag  uint32
    34  	Oflag  uint32
    35  	Cflag  uint32
    36  	Lflag  uint32
    37  	Cc     [20]byte
    38  	Ispeed uint32
    39  	Ospeed uint32
    40  }
    41  
    42  // MakeRaw put the terminal connected to the given file descriptor into raw
    43  // mode and returns the previous state of the terminal so that it can be
    44  // restored.
    45  func MakeRaw(fd uintptr) (*State, error) {
    46  	var oldState State
    47  	if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, fd, uintptr(getTermios), uintptr(unsafe.Pointer(&oldState.termios))); err != 0 {
    48  		return nil, err
    49  	}
    50  
    51  	newState := oldState.termios
    52  	newState.Iflag &^= (IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON)
    53  	newState.Oflag &^= OPOST
    54  	newState.Lflag &^= (ECHO | ECHONL | ICANON | ISIG | IEXTEN)
    55  	newState.Cflag &^= (CSIZE | PARENB)
    56  	newState.Cflag |= CS8
    57  	newState.Cc[syscall.VMIN] = 1
    58  	newState.Cc[syscall.VTIME] = 0
    59  
    60  	if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, fd, uintptr(setTermios), uintptr(unsafe.Pointer(&newState))); err != 0 {
    61  		return nil, err
    62  	}
    63  
    64  	return &oldState, nil
    65  }