Browse code

Fixing newlines in attached mode

shin- authored on 2013/03/22 20:24:03
Showing 3 changed files
... ...
@@ -114,27 +114,6 @@ func IsTerminal(fd int) bool {
114 114
 	return err == 0
115 115
 }
116 116
 
117
-// MakeRaw put the terminal connected to the given file descriptor into raw
118
-// mode and returns the previous state of the terminal so that it can be
119
-// restored.
120
-func MakeRaw(fd int) (*State, error) {
121
-	var oldState State
122
-	if _, _, err := syscall.Syscall6(syscall.SYS_IOCTL, uintptr(fd), uintptr(getTermios), uintptr(unsafe.Pointer(&oldState.termios)), 0, 0, 0); err != 0 {
123
-		return nil, err
124
-	}
125
-
126
-	newState := oldState.termios
127
-	newState.Iflag &^= ISTRIP | INLCR | IGNCR | IXON | IXOFF
128
-	newState.Iflag |= ICRNL
129
-	newState.Oflag |= ONLCR
130
-	newState.Lflag &^= ECHO | ICANON | ISIG
131
-	if _, _, err := syscall.Syscall6(syscall.SYS_IOCTL, uintptr(fd), uintptr(setTermios), uintptr(unsafe.Pointer(&newState)), 0, 0, 0); err != 0 {
132
-		return nil, err
133
-	}
134
-
135
-	return &oldState, nil
136
-}
137
-
138 117
 // Restore restores the terminal connected to the given file descriptor to a
139 118
 // previous state.
140 119
 func Restore(fd int, state *State) error {
... ...
@@ -1,8 +1,32 @@
1 1
 package term
2 2
 
3
-import "syscall"
3
+import (
4
+    "syscall"
5
+    "unsafe"
6
+)
4 7
 
5 8
 const (
6 9
 	getTermios = syscall.TIOCGETA
7 10
 	setTermios = syscall.TIOCSETA
8 11
 )
12
+
13
+// MakeRaw put the terminal connected to the given file descriptor into raw
14
+// mode and returns the previous state of the terminal so that it can be
15
+// restored.
16
+func MakeRaw(fd int) (*State, error) {
17
+    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 {
19
+        return nil, err
20
+    }
21
+
22
+    newState := oldState.termios
23
+    newState.Iflag &^= ISTRIP | INLCR | IGNCR | IXON | IXOFF
24
+    newState.Iflag |= ICRNL
25
+    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 {
28
+        return nil, err
29
+    }
30
+
31
+    return &oldState, nil
32
+}
9 33
\ No newline at end of file
... ...
@@ -1,8 +1,32 @@
1 1
 package term
2 2
 
3
-import "syscall"
3
+import (
4
+    "syscall"
5
+    "unsafe"
6
+)
4 7
 
5 8
 const (
6 9
 	getTermios = syscall.TCGETS
7 10
 	setTermios = syscall.TCSETS
8 11
 )
12
+
13
+// MakeRaw put the terminal connected to the given file descriptor into raw
14
+// mode and returns the previous state of the terminal so that it can be
15
+// restored.
16
+func MakeRaw(fd int) (*State, error) {
17
+    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 {
19
+        return nil, err
20
+    }
21
+
22
+    newState := oldState.termios
23
+    newState.Iflag &^= ISTRIP | IXON | IXOFF
24
+    newState.Iflag |= ICRNL
25
+    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 {
28
+        return nil, err
29
+    }
30
+
31
+    return &oldState, nil
32
+}
9 33
\ No newline at end of file