moby--moby/term/termios_linux.go

32 lines
915 B
Go
Raw Normal View History

package term
2013-01-29 01:06:46 +00:00
2013-03-22 11:24:03 +00:00
import (
"syscall"
"unsafe"
)
2013-01-29 01:06:46 +00:00
const (
getTermios = syscall.TCGETS
setTermios = syscall.TCSETS
)
2013-03-22 11:24:03 +00: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.
func MakeRaw(fd int) (*State, error) {
var oldState State
if _, _, err := syscall.Syscall6(syscall.SYS_IOCTL, uintptr(fd), uintptr(getTermios), uintptr(unsafe.Pointer(&oldState.termios)), 0, 0, 0); err != 0 {
return nil, err
}
newState := oldState.termios
newState.Iflag &^= ISTRIP | IXON | IXOFF
newState.Iflag |= ICRNL
newState.Oflag |= ONLCR
newState.Lflag &^= ECHO | ICANON | ISIG
if _, _, err := syscall.Syscall6(syscall.SYS_IOCTL, uintptr(fd), uintptr(setTermios), uintptr(unsafe.Pointer(&newState)), 0, 0, 0); err != 0 {
return nil, err
}
return &oldState, nil
}