github.com/reds/docker@v1.11.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  
    13  // Termios magic numbers, passthrough to the ones defined in syscall.
    14  const (
    15  	IGNBRK = syscall.IGNBRK
    16  	PARMRK = syscall.PARMRK
    17  	INLCR  = syscall.INLCR
    18  	IGNCR  = syscall.IGNCR
    19  	ECHONL = syscall.ECHONL
    20  	CSIZE  = syscall.CSIZE
    21  	ICRNL  = syscall.ICRNL
    22  	ISTRIP = syscall.ISTRIP
    23  	PARENB = syscall.PARENB
    24  	ECHO   = syscall.ECHO
    25  	ICANON = syscall.ICANON
    26  	ISIG   = syscall.ISIG
    27  	IXON   = syscall.IXON
    28  	BRKINT = syscall.BRKINT
    29  	INPCK  = syscall.INPCK
    30  	OPOST  = syscall.OPOST
    31  	CS8    = syscall.CS8
    32  	IEXTEN = syscall.IEXTEN
    33  )
    34  
    35  // Termios is the Unix API for terminal I/O.
    36  type Termios struct {
    37  	Iflag  uint32
    38  	Oflag  uint32
    39  	Cflag  uint32
    40  	Lflag  uint32
    41  	Cc     [20]byte
    42  	Ispeed uint32
    43  	Ospeed uint32
    44  }
    45  
    46  // MakeRaw put the terminal connected to the given file descriptor into raw
    47  // mode and returns the previous state of the terminal so that it can be
    48  // restored.
    49  func MakeRaw(fd uintptr) (*State, error) {
    50  	var oldState State
    51  	if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, fd, uintptr(getTermios), uintptr(unsafe.Pointer(&oldState.termios))); err != 0 {
    52  		return nil, err
    53  	}
    54  
    55  	newState := oldState.termios
    56  	newState.Iflag &^= (IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON)
    57  	newState.Oflag &^= OPOST
    58  	newState.Lflag &^= (ECHO | ECHONL | ICANON | ISIG | IEXTEN)
    59  	newState.Cflag &^= (CSIZE | PARENB)
    60  	newState.Cflag |= CS8
    61  	newState.Cc[syscall.VMIN] = 1
    62  	newState.Cc[syscall.VTIME] = 0
    63  
    64  	if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, fd, uintptr(setTermios), uintptr(unsafe.Pointer(&newState))); err != 0 {
    65  		return nil, err
    66  	}
    67  
    68  	return &oldState, nil
    69  }