Use BSD raw mode on darwin. Fixes nano, tmux and others

Docker-DCO-1.1-Signed-off-by: Guillaume J. Charmes <guillaume@charmes.net> (github: creack)
This commit is contained in:
Guillaume J. Charmes 2014-03-13 11:11:02 -07:00
parent 51a46e6a4f
commit 029aac9639
No known key found for this signature in database
GPG Key ID: B33E4642CB6E3FF3
2 changed files with 25 additions and 16 deletions

View File

@ -9,16 +9,24 @@ const (
getTermios = syscall.TIOCGETA getTermios = syscall.TIOCGETA
setTermios = syscall.TIOCSETA setTermios = syscall.TIOCSETA
ECHO = 0x00000008 IGNBRK = syscall.IGNBRK
ONLCR = 0x2 PARMRK = syscall.PARMRK
ISTRIP = 0x20 INLCR = syscall.INLCR
INLCR = 0x40 IGNCR = syscall.IGNCR
ISIG = 0x80 ECHONL = syscall.ECHONL
IGNCR = 0x80 CSIZE = syscall.CSIZE
ICANON = 0x100 ICRNL = syscall.ICRNL
ICRNL = 0x100 ISTRIP = syscall.ISTRIP
IXOFF = 0x400 PARENB = syscall.PARENB
IXON = 0x200 ECHO = syscall.ECHO
ICANON = syscall.ICANON
ISIG = syscall.ISIG
IXON = syscall.IXON
BRKINT = syscall.BRKINT
INPCK = syscall.INPCK
OPOST = syscall.OPOST
CS8 = syscall.CS8
IEXTEN = syscall.IEXTEN
) )
type Termios struct { type Termios struct {
@ -41,10 +49,13 @@ func MakeRaw(fd uintptr) (*State, error) {
} }
newState := oldState.termios newState := oldState.termios
newState.Iflag &^= (ISTRIP | INLCR | IGNCR | IXON | IXOFF) newState.Iflag &^= (IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON)
newState.Iflag |= ICRNL newState.Oflag &^= OPOST
newState.Oflag |= ONLCR newState.Lflag &^= (ECHO | ECHONL | ICANON | ISIG | IEXTEN)
newState.Lflag &^= (ECHO | ICANON | ISIG) newState.Cflag &^= (CSIZE | PARENB)
newState.Cflag |= CS8
newState.Cc[syscall.VMIN] = 1
newState.Cc[syscall.VTIME] = 0
if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, fd, uintptr(setTermios), uintptr(unsafe.Pointer(&newState))); err != 0 { if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, fd, uintptr(setTermios), uintptr(unsafe.Pointer(&newState))); err != 0 {
return nil, err return nil, err

View File

@ -47,8 +47,6 @@ func MakeRaw(fd uintptr) (*State, error) {
if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, fd, uintptr(getTermios), uintptr(unsafe.Pointer(&oldState.termios))); err != 0 { if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, fd, uintptr(getTermios), uintptr(unsafe.Pointer(&oldState.termios))); err != 0 {
return nil, err return nil, err
} }
// C.makeraw()
// return &oldState, nil
newState := oldState.termios newState := oldState.termios
newState.Iflag &^= (IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON) newState.Iflag &^= (IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON)