Browse code

Move Termios struct to os specific file

Guillaume J. Charmes authored on 2013/06/02 08:19:50
Showing 3 changed files
... ...
@@ -7,16 +7,6 @@ import (
7 7
 	"unsafe"
8 8
 )
9 9
 
10
-type Termios struct {
11
-	Iflag  uint32
12
-	Oflag  uint32
13
-	Cflag  uint32
14
-	Lflag  uint32
15
-	Cc     [20]byte
16
-	Ispeed uint32
17
-	Ospeed uint32
18
-}
19
-
20 10
 type State struct {
21 11
 	termios Termios
22 12
 }
... ...
@@ -8,23 +8,45 @@ import (
8 8
 const (
9 9
 	getTermios = syscall.TIOCGETA
10 10
 	setTermios = syscall.TIOCSETA
11
+
12
+	ECHO    = 0x00000008
13
+	ONLCR   = 0x2
14
+	ISTRIP  = 0x20
15
+	INLCR   = 0x40
16
+	ISIG    = 0x80
17
+	IGNCR   = 0x80
18
+	ICANON  = 0x100
19
+	ICRNL   = 0x100
20
+	IXOFF   = 0x400
21
+	IXON    = 0x200
11 22
 )
12 23
 
24
+type Termios struct {
25
+	Iflag  uint64
26
+	Oflag  uint64
27
+	Cflag  uint64
28
+	Lflag  uint64
29
+	Cc     [20]byte
30
+	Ispeed uint64
31
+	Ospeed uint64
32
+}
33
+
13 34
 // MakeRaw put the terminal connected to the given file descriptor into raw
14 35
 // mode and returns the previous state of the terminal so that it can be
15 36
 // restored.
16
-func MakeRaw(fd int) (*State, error) {
37
+func MakeRaw(fd uintptr) (*State, error) {
17 38
 	var oldState State
18
-	if _, _, err := syscall.Syscall6(syscall.SYS_IOCTL, uintptr(fd), uintptr(getTermios), uintptr(unsafe.Pointer(&oldState.termios)), 0, 0, 0); err != 0 {
39
+	if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, fd, uintptr(getTermios), uintptr(unsafe.Pointer(&oldState.termios))); err != 0 {
19 40
 		return nil, err
20 41
 	}
21 42
 
22 43
 	newState := oldState.termios
23
-	newState.Iflag &^= ISTRIP | INLCR | IGNCR | IXON | IXOFF
44
+	newState.Iflag &^= (ISTRIP | INLCR | IGNCR | IXON | IXOFF)
24 45
 	newState.Iflag |= ICRNL
25 46
 	newState.Oflag |= ONLCR
26
-	newState.Lflag &^= ECHO | ICANON | ISIG
27
-	if _, _, err := syscall.Syscall6(syscall.SYS_IOCTL, uintptr(fd), uintptr(setTermios), uintptr(unsafe.Pointer(&newState)), 0, 0, 0); err != 0 {
47
+	newState.Lflag &^= (ECHO | ICANON | ISIG)
48
+
49
+	if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, fd, uintptr(setTermios), uintptr(unsafe.Pointer(&newState))); err != 0 {
28 50
 		return nil, err
29 51
 	}
30 52
 
... ...
@@ -10,6 +10,16 @@ const (
10 10
 	setTermios = syscall.TCSETS
11 11
 )
12 12
 
13
+type Termios struct {
14
+	Iflag  uint32
15
+	Oflag  uint32
16
+	Cflag  uint32
17
+	Lflag  uint32
18
+	Cc     [20]byte
19
+	Ispeed uint32
20
+	Ospeed uint32
21
+}
22
+
13 23
 // MakeRaw put the terminal connected to the given file descriptor into raw
14 24
 // mode and returns the previous state of the terminal so that it can be
15 25
 // restored.