1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00
moby--moby/term/termios_darwin.go

33 lines
885 B
Go
Raw Normal View History

package term
2013-01-28 20:06:46 -05:00
2013-03-22 07:24:03 -04:00
import (
2013-03-30 02:58:30 -04:00
"syscall"
"unsafe"
2013-03-22 07:24:03 -04:00
)
2013-01-28 20:07:38 -05:00
2013-01-28 20:06:46 -05:00
const (
2013-01-28 21:37:54 -05:00
getTermios = syscall.TIOCGETA
setTermios = syscall.TIOCSETA
2013-01-28 20:06:46 -05:00
)
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.
func MakeRaw(fd int) (*State, error) {
2013-03-30 02:58:30 -04:00
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
}
2013-03-22 07:24:03 -04:00
2013-03-30 02:58:30 -04:00
newState := oldState.termios
newState.Iflag &^= ISTRIP | INLCR | IGNCR | 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
}
2013-03-22 07:24:03 -04:00
2013-03-30 02:58:30 -04:00
return &oldState, nil
}