Remove cgo from term
This commit is contained in:
parent
078a19d725
commit
64f346779f
12
term/term.go
12
term/term.go
|
@ -8,13 +8,13 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type Termios struct {
|
type Termios struct {
|
||||||
Iflag uintptr
|
Iflag uint32
|
||||||
Oflag uintptr
|
Oflag uint32
|
||||||
Cflag uintptr
|
Cflag uint32
|
||||||
Lflag uintptr
|
Lflag uint32
|
||||||
Cc [20]byte
|
Cc [20]byte
|
||||||
Ispeed uintptr
|
Ispeed uint32
|
||||||
Ospeed uintptr
|
Ospeed uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
|
@ -5,26 +5,6 @@ import (
|
||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
// #include <termios.h>
|
|
||||||
// #include <sys/ioctl.h>
|
|
||||||
/*
|
|
||||||
void MakeRaw(int fd) {
|
|
||||||
struct termios t;
|
|
||||||
|
|
||||||
// FIXME: Handle errors?
|
|
||||||
ioctl(fd, TCGETS, &t);
|
|
||||||
|
|
||||||
t.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON);
|
|
||||||
t.c_oflag &= ~OPOST;
|
|
||||||
t.c_lflag &= ~(ECHO | ECHONL | ICANON | IEXTEN | ISIG);
|
|
||||||
t.c_cflag &= ~(CSIZE | PARENB);
|
|
||||||
t.c_cflag |= CS8;
|
|
||||||
|
|
||||||
ioctl(fd, TCSETS, &t);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
import "C"
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
getTermios = syscall.TCGETS
|
getTermios = syscall.TCGETS
|
||||||
setTermios = syscall.TCSETS
|
setTermios = syscall.TCSETS
|
||||||
|
@ -35,24 +15,20 @@ const (
|
||||||
// restored.
|
// restored.
|
||||||
func MakeRaw(fd int) (*State, error) {
|
func MakeRaw(fd int) (*State, error) {
|
||||||
var oldState State
|
var oldState State
|
||||||
if _, _, err := syscall.Syscall6(syscall.SYS_IOCTL, uintptr(fd), syscall.TCGETS, uintptr(unsafe.Pointer(&oldState.termios)), 0, 0, 0); err != 0 {
|
if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, uintptr(fd), getTermios, uintptr(unsafe.Pointer(&oldState.termios))); err != 0 {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
newState := oldState.termios
|
||||||
|
|
||||||
|
newState.Iflag &^= (syscall.IGNBRK | syscall.BRKINT | syscall.PARMRK | syscall.ISTRIP | syscall.INLCR | syscall.IGNCR | syscall.ICRNL | syscall.IXON)
|
||||||
|
newState.Oflag &^= syscall.OPOST
|
||||||
|
newState.Lflag &^= (syscall.ECHO | syscall.ECHONL | syscall.ICANON | syscall.ISIG | syscall.IEXTEN)
|
||||||
|
newState.Cflag &^= (syscall.CSIZE | syscall.PARENB)
|
||||||
|
newState.Cflag |= syscall.CS8
|
||||||
|
|
||||||
|
if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, uintptr(fd), setTermios, uintptr(unsafe.Pointer(&newState))); err != 0 {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
C.MakeRaw(C.int(fd))
|
|
||||||
return &oldState, nil
|
return &oldState, nil
|
||||||
|
|
||||||
// FIXME: post on goland issues this: very same as the C function bug non-working
|
|
||||||
|
|
||||||
// newState := oldState.termios
|
|
||||||
|
|
||||||
// newState.Iflag &^= (IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON)
|
|
||||||
// newState.Oflag &^= OPOST
|
|
||||||
// newState.Lflag &^= (ECHO | syscall.ECHONL | ICANON | ISIG | IEXTEN)
|
|
||||||
// newState.Cflag &^= (CSIZE | syscall.PARENB)
|
|
||||||
// newState.Cflag |= CS8
|
|
||||||
|
|
||||||
// if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, uintptr(fd), syscall.TCSETS, uintptr(unsafe.Pointer(&newState))); err != 0 {
|
|
||||||
// return nil, err
|
|
||||||
// }
|
|
||||||
// return &oldState, nil
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue