| ... | ... |
@@ -1,7 +1,6 @@ |
| 1 | 1 |
package term |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 |
- "os" |
|
| 5 | 4 |
"syscall" |
| 6 | 5 |
"unsafe" |
| 7 | 6 |
) |
| ... | ... |
@@ -9,11 +8,11 @@ import ( |
| 9 | 9 |
// #include <termios.h> |
| 10 | 10 |
// #include <sys/ioctl.h> |
| 11 | 11 |
/* |
| 12 |
-void MakeRaw() {
|
|
| 12 |
+void MakeRaw(int fd) {
|
|
| 13 | 13 |
struct termios t; |
| 14 | 14 |
|
| 15 | 15 |
// FIXME: Handle errors? |
| 16 |
- ioctl(0, TCGETS, &t); |
|
| 16 |
+ ioctl(fd, TCGETS, &t); |
|
| 17 | 17 |
|
| 18 | 18 |
t.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON); |
| 19 | 19 |
t.c_oflag &= ~OPOST; |
| ... | ... |
@@ -21,7 +20,7 @@ void MakeRaw() {
|
| 21 | 21 |
t.c_cflag &= ~(CSIZE | PARENB); |
| 22 | 22 |
t.c_cflag |= CS8; |
| 23 | 23 |
|
| 24 |
- ioctl(0, TCSETS, &t); |
|
| 24 |
+ ioctl(fd, TCSETS, &t); |
|
| 25 | 25 |
} |
| 26 | 26 |
*/ |
| 27 | 27 |
import "C" |
| ... | ... |
@@ -35,14 +34,11 @@ const ( |
| 35 | 35 |
// mode and returns the previous state of the terminal so that it can be |
| 36 | 36 |
// restored. |
| 37 | 37 |
func MakeRaw(fd int) (*State, error) {
|
| 38 |
- |
|
| 39 |
- fd = int(os.Stdin.Fd()) |
|
| 40 |
- |
|
| 41 | 38 |
var oldState State |
| 42 | 39 |
if _, _, err := syscall.Syscall6(syscall.SYS_IOCTL, uintptr(fd), syscall.TCGETS, uintptr(unsafe.Pointer(&oldState.termios)), 0, 0, 0); err != 0 {
|
| 43 | 40 |
return nil, err |
| 44 | 41 |
} |
| 45 |
- C.MakeRaw() |
|
| 42 |
+ C.MakeRaw(C.int(fd)) |
|
| 46 | 43 |
return &oldState, nil |
| 47 | 44 |
|
| 48 | 45 |
// FIXME: post on goland issues this: very same as the C function bug non-working |