Signed-off-by: Tibor Vass <tibor@docker.com>
| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,42 @@ |
| 0 |
+// +build darwin freebsd openbsd |
|
| 1 |
+ |
|
| 2 |
+package term |
|
| 3 |
+ |
|
| 4 |
+import ( |
|
| 5 |
+ "unsafe" |
|
| 6 |
+ |
|
| 7 |
+ "golang.org/x/sys/unix" |
|
| 8 |
+) |
|
| 9 |
+ |
|
| 10 |
+const ( |
|
| 11 |
+ getTermios = unix.TIOCGETA |
|
| 12 |
+ setTermios = unix.TIOCSETA |
|
| 13 |
+) |
|
| 14 |
+ |
|
| 15 |
+// Termios is the Unix API for terminal I/O. |
|
| 16 |
+type Termios unix.Termios |
|
| 17 |
+ |
|
| 18 |
+// MakeRaw put the terminal connected to the given file descriptor into raw |
|
| 19 |
+// mode and returns the previous state of the terminal so that it can be |
|
| 20 |
+// restored. |
|
| 21 |
+func MakeRaw(fd uintptr) (*State, error) {
|
|
| 22 |
+ var oldState State |
|
| 23 |
+ if _, _, err := unix.Syscall(unix.SYS_IOCTL, fd, getTermios, uintptr(unsafe.Pointer(&oldState.termios))); err != 0 {
|
|
| 24 |
+ return nil, err |
|
| 25 |
+ } |
|
| 26 |
+ |
|
| 27 |
+ newState := oldState.termios |
|
| 28 |
+ newState.Iflag &^= (unix.IGNBRK | unix.BRKINT | unix.PARMRK | unix.ISTRIP | unix.INLCR | unix.IGNCR | unix.ICRNL | unix.IXON) |
|
| 29 |
+ newState.Oflag &^= unix.OPOST |
|
| 30 |
+ newState.Lflag &^= (unix.ECHO | unix.ECHONL | unix.ICANON | unix.ISIG | unix.IEXTEN) |
|
| 31 |
+ newState.Cflag &^= (unix.CSIZE | unix.PARENB) |
|
| 32 |
+ newState.Cflag |= unix.CS8 |
|
| 33 |
+ newState.Cc[unix.VMIN] = 1 |
|
| 34 |
+ newState.Cc[unix.VTIME] = 0 |
|
| 35 |
+ |
|
| 36 |
+ if _, _, err := unix.Syscall(unix.SYS_IOCTL, fd, setTermios, uintptr(unsafe.Pointer(&newState))); err != 0 {
|
|
| 37 |
+ return nil, err |
|
| 38 |
+ } |
|
| 39 |
+ |
|
| 40 |
+ return &oldState, nil |
|
| 41 |
+} |
| 0 | 42 |
deleted file mode 100644 |
| ... | ... |
@@ -1,70 +0,0 @@ |
| 1 |
-package term |
|
| 2 |
- |
|
| 3 |
-import ( |
|
| 4 |
- "unsafe" |
|
| 5 |
- |
|
| 6 |
- "golang.org/x/sys/unix" |
|
| 7 |
-) |
|
| 8 |
- |
|
| 9 |
-const ( |
|
| 10 |
- getTermios = unix.TIOCGETA |
|
| 11 |
- setTermios = unix.TIOCSETA |
|
| 12 |
-) |
|
| 13 |
- |
|
| 14 |
-// Termios magic numbers, passthrough to the ones defined in unix. |
|
| 15 |
-const ( |
|
| 16 |
- IGNBRK = unix.IGNBRK |
|
| 17 |
- PARMRK = unix.PARMRK |
|
| 18 |
- INLCR = unix.INLCR |
|
| 19 |
- IGNCR = unix.IGNCR |
|
| 20 |
- ECHONL = unix.ECHONL |
|
| 21 |
- CSIZE = unix.CSIZE |
|
| 22 |
- ICRNL = unix.ICRNL |
|
| 23 |
- ISTRIP = unix.ISTRIP |
|
| 24 |
- PARENB = unix.PARENB |
|
| 25 |
- ECHO = unix.ECHO |
|
| 26 |
- ICANON = unix.ICANON |
|
| 27 |
- ISIG = unix.ISIG |
|
| 28 |
- IXON = unix.IXON |
|
| 29 |
- BRKINT = unix.BRKINT |
|
| 30 |
- INPCK = unix.INPCK |
|
| 31 |
- OPOST = unix.OPOST |
|
| 32 |
- CS8 = unix.CS8 |
|
| 33 |
- IEXTEN = unix.IEXTEN |
|
| 34 |
-) |
|
| 35 |
- |
|
| 36 |
-// Termios is the Unix API for terminal I/O. |
|
| 37 |
-type Termios struct {
|
|
| 38 |
- Iflag uint64 |
|
| 39 |
- Oflag uint64 |
|
| 40 |
- Cflag uint64 |
|
| 41 |
- Lflag uint64 |
|
| 42 |
- Cc [20]byte |
|
| 43 |
- Ispeed uint64 |
|
| 44 |
- Ospeed uint64 |
|
| 45 |
-} |
|
| 46 |
- |
|
| 47 |
-// MakeRaw put the terminal connected to the given file descriptor into raw |
|
| 48 |
-// mode and returns the previous state of the terminal so that it can be |
|
| 49 |
-// restored. |
|
| 50 |
-func MakeRaw(fd uintptr) (*State, error) {
|
|
| 51 |
- var oldState State |
|
| 52 |
- if _, _, err := unix.Syscall(unix.SYS_IOCTL, fd, uintptr(getTermios), uintptr(unsafe.Pointer(&oldState.termios))); err != 0 {
|
|
| 53 |
- return nil, err |
|
| 54 |
- } |
|
| 55 |
- |
|
| 56 |
- newState := oldState.termios |
|
| 57 |
- newState.Iflag &^= (IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON) |
|
| 58 |
- newState.Oflag &^= OPOST |
|
| 59 |
- newState.Lflag &^= (ECHO | ECHONL | ICANON | ISIG | IEXTEN) |
|
| 60 |
- newState.Cflag &^= (CSIZE | PARENB) |
|
| 61 |
- newState.Cflag |= CS8 |
|
| 62 |
- newState.Cc[unix.VMIN] = 1 |
|
| 63 |
- newState.Cc[unix.VTIME] = 0 |
|
| 64 |
- |
|
| 65 |
- if _, _, err := unix.Syscall(unix.SYS_IOCTL, fd, uintptr(setTermios), uintptr(unsafe.Pointer(&newState))); err != 0 {
|
|
| 66 |
- return nil, err |
|
| 67 |
- } |
|
| 68 |
- |
|
| 69 |
- return &oldState, nil |
|
| 70 |
-} |
| 71 | 1 |
deleted file mode 100644 |
| ... | ... |
@@ -1,70 +0,0 @@ |
| 1 |
-package term |
|
| 2 |
- |
|
| 3 |
-import ( |
|
| 4 |
- "unsafe" |
|
| 5 |
- |
|
| 6 |
- "golang.org/x/sys/unix" |
|
| 7 |
-) |
|
| 8 |
- |
|
| 9 |
-const ( |
|
| 10 |
- getTermios = unix.TIOCGETA |
|
| 11 |
- setTermios = unix.TIOCSETA |
|
| 12 |
-) |
|
| 13 |
- |
|
| 14 |
-// Termios magic numbers, passthrough to the ones defined in unix. |
|
| 15 |
-const ( |
|
| 16 |
- IGNBRK = unix.IGNBRK |
|
| 17 |
- PARMRK = unix.PARMRK |
|
| 18 |
- INLCR = unix.INLCR |
|
| 19 |
- IGNCR = unix.IGNCR |
|
| 20 |
- ECHONL = unix.ECHONL |
|
| 21 |
- CSIZE = unix.CSIZE |
|
| 22 |
- ICRNL = unix.ICRNL |
|
| 23 |
- ISTRIP = unix.ISTRIP |
|
| 24 |
- PARENB = unix.PARENB |
|
| 25 |
- ECHO = unix.ECHO |
|
| 26 |
- ICANON = unix.ICANON |
|
| 27 |
- ISIG = unix.ISIG |
|
| 28 |
- IXON = unix.IXON |
|
| 29 |
- BRKINT = unix.BRKINT |
|
| 30 |
- INPCK = unix.INPCK |
|
| 31 |
- OPOST = unix.OPOST |
|
| 32 |
- CS8 = unix.CS8 |
|
| 33 |
- IEXTEN = unix.IEXTEN |
|
| 34 |
-) |
|
| 35 |
- |
|
| 36 |
-// Termios is the Unix API for terminal I/O. |
|
| 37 |
-type Termios struct {
|
|
| 38 |
- Iflag uint32 |
|
| 39 |
- Oflag uint32 |
|
| 40 |
- Cflag uint32 |
|
| 41 |
- Lflag uint32 |
|
| 42 |
- Cc [20]byte |
|
| 43 |
- Ispeed uint32 |
|
| 44 |
- Ospeed uint32 |
|
| 45 |
-} |
|
| 46 |
- |
|
| 47 |
-// MakeRaw put the terminal connected to the given file descriptor into raw |
|
| 48 |
-// mode and returns the previous state of the terminal so that it can be |
|
| 49 |
-// restored. |
|
| 50 |
-func MakeRaw(fd uintptr) (*State, error) {
|
|
| 51 |
- var oldState State |
|
| 52 |
- if _, _, err := unix.Syscall(unix.SYS_IOCTL, fd, uintptr(getTermios), uintptr(unsafe.Pointer(&oldState.termios))); err != 0 {
|
|
| 53 |
- return nil, err |
|
| 54 |
- } |
|
| 55 |
- |
|
| 56 |
- newState := oldState.termios |
|
| 57 |
- newState.Iflag &^= (IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON) |
|
| 58 |
- newState.Oflag &^= OPOST |
|
| 59 |
- newState.Lflag &^= (ECHO | ECHONL | ICANON | ISIG | IEXTEN) |
|
| 60 |
- newState.Cflag &^= (CSIZE | PARENB) |
|
| 61 |
- newState.Cflag |= CS8 |
|
| 62 |
- newState.Cc[unix.VMIN] = 1 |
|
| 63 |
- newState.Cc[unix.VTIME] = 0 |
|
| 64 |
- |
|
| 65 |
- if _, _, err := unix.Syscall(unix.SYS_IOCTL, fd, uintptr(setTermios), uintptr(unsafe.Pointer(&newState))); err != 0 {
|
|
| 66 |
- return nil, err |
|
| 67 |
- } |
|
| 68 |
- |
|
| 69 |
- return &oldState, nil |
|
| 70 |
-} |
| ... | ... |
@@ -12,15 +12,7 @@ const ( |
| 12 | 12 |
) |
| 13 | 13 |
|
| 14 | 14 |
// Termios is the Unix API for terminal I/O. |
| 15 |
-type Termios struct {
|
|
| 16 |
- Iflag uint32 |
|
| 17 |
- Oflag uint32 |
|
| 18 |
- Cflag uint32 |
|
| 19 |
- Lflag uint32 |
|
| 20 |
- Cc [20]byte |
|
| 21 |
- Ispeed uint32 |
|
| 22 |
- Ospeed uint32 |
|
| 23 |
-} |
|
| 15 |
+type Termios unix.Termios |
|
| 24 | 16 |
|
| 25 | 17 |
// MakeRaw put the terminal connected to the given file descriptor into raw |
| 26 | 18 |
// mode and returns the previous state of the terminal so that it can be |
| 27 | 19 |
deleted file mode 100644 |
| ... | ... |
@@ -1,70 +0,0 @@ |
| 1 |
-package term |
|
| 2 |
- |
|
| 3 |
-import ( |
|
| 4 |
- "unsafe" |
|
| 5 |
- |
|
| 6 |
- "golang.org/x/sys/unix" |
|
| 7 |
-) |
|
| 8 |
- |
|
| 9 |
-const ( |
|
| 10 |
- getTermios = unix.TIOCGETA |
|
| 11 |
- setTermios = unix.TIOCSETA |
|
| 12 |
-) |
|
| 13 |
- |
|
| 14 |
-// Termios magic numbers, passthrough to the ones defined in unix. |
|
| 15 |
-const ( |
|
| 16 |
- IGNBRK = unix.IGNBRK |
|
| 17 |
- PARMRK = unix.PARMRK |
|
| 18 |
- INLCR = unix.INLCR |
|
| 19 |
- IGNCR = unix.IGNCR |
|
| 20 |
- ECHONL = unix.ECHONL |
|
| 21 |
- CSIZE = unix.CSIZE |
|
| 22 |
- ICRNL = unix.ICRNL |
|
| 23 |
- ISTRIP = unix.ISTRIP |
|
| 24 |
- PARENB = unix.PARENB |
|
| 25 |
- ECHO = unix.ECHO |
|
| 26 |
- ICANON = unix.ICANON |
|
| 27 |
- ISIG = unix.ISIG |
|
| 28 |
- IXON = unix.IXON |
|
| 29 |
- BRKINT = unix.BRKINT |
|
| 30 |
- INPCK = unix.INPCK |
|
| 31 |
- OPOST = unix.OPOST |
|
| 32 |
- CS8 = unix.CS8 |
|
| 33 |
- IEXTEN = unix.IEXTEN |
|
| 34 |
-) |
|
| 35 |
- |
|
| 36 |
-// Termios is the Unix API for terminal I/O. |
|
| 37 |
-type Termios struct {
|
|
| 38 |
- Iflag uint32 |
|
| 39 |
- Oflag uint32 |
|
| 40 |
- Cflag uint32 |
|
| 41 |
- Lflag uint32 |
|
| 42 |
- Cc [20]byte |
|
| 43 |
- Ispeed uint32 |
|
| 44 |
- Ospeed uint32 |
|
| 45 |
-} |
|
| 46 |
- |
|
| 47 |
-// MakeRaw put the terminal connected to the given file descriptor into raw |
|
| 48 |
-// mode and returns the previous state of the terminal so that it can be |
|
| 49 |
-// restored. |
|
| 50 |
-func MakeRaw(fd uintptr) (*State, error) {
|
|
| 51 |
- var oldState State |
|
| 52 |
- if _, _, err := unix.Syscall(unix.SYS_IOCTL, fd, uintptr(getTermios), uintptr(unsafe.Pointer(&oldState.termios))); err != 0 {
|
|
| 53 |
- return nil, err |
|
| 54 |
- } |
|
| 55 |
- |
|
| 56 |
- newState := oldState.termios |
|
| 57 |
- newState.Iflag &^= (IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON) |
|
| 58 |
- newState.Oflag &^= OPOST |
|
| 59 |
- newState.Lflag &^= (ECHO | ECHONL | ICANON | ISIG | IEXTEN) |
|
| 60 |
- newState.Cflag &^= (CSIZE | PARENB) |
|
| 61 |
- newState.Cflag |= CS8 |
|
| 62 |
- newState.Cc[unix.VMIN] = 1 |
|
| 63 |
- newState.Cc[unix.VTIME] = 0 |
|
| 64 |
- |
|
| 65 |
- if _, _, err := unix.Syscall(unix.SYS_IOCTL, fd, uintptr(setTermios), uintptr(unsafe.Pointer(&newState))); err != 0 {
|
|
| 66 |
- return nil, err |
|
| 67 |
- } |
|
| 68 |
- |
|
| 69 |
- return &oldState, nil |
|
| 70 |
-} |