Switches calls to syscall to x/sys, which is more up to date.
This is fixes a number of possible bugs on other architectures
where ioctl tcget and tcset aren't implemented correctly.
There are a few remaining syscall references, because x/sys doesn't
have an Errno implementation yet.
Also removes a ppc64le and cgo build tag that fixes building on
ppc64le without cgo
Signed-off-by: Christopher Jones <tophj@linux.vnet.ibm.com>
| 1 | 1 |
deleted file mode 100644 |
| ... | ... |
@@ -1,51 +0,0 @@ |
| 1 |
-// +build linux,cgo |
|
| 2 |
- |
|
| 3 |
-package term |
|
| 4 |
- |
|
| 5 |
-import ( |
|
| 6 |
- "syscall" |
|
| 7 |
- "unsafe" |
|
| 8 |
-) |
|
| 9 |
- |
|
| 10 |
-// #include <termios.h> |
|
| 11 |
-import "C" |
|
| 12 |
- |
|
| 13 |
-// Termios is the Unix API for terminal I/O. |
|
| 14 |
-// It is passthrough for syscall.Termios in order to make it portable with |
|
| 15 |
-// other platforms where it is not available or handled differently. |
|
| 16 |
-type Termios syscall.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 := tcget(fd, &oldState.termios); err != 0 {
|
|
| 24 |
- return nil, err |
|
| 25 |
- } |
|
| 26 |
- |
|
| 27 |
- newState := oldState.termios |
|
| 28 |
- |
|
| 29 |
- C.cfmakeraw((*C.struct_termios)(unsafe.Pointer(&newState))) |
|
| 30 |
- newState.Oflag = newState.Oflag | C.OPOST |
|
| 31 |
- if err := tcset(fd, &newState); err != 0 {
|
|
| 32 |
- return nil, err |
|
| 33 |
- } |
|
| 34 |
- return &oldState, nil |
|
| 35 |
-} |
|
| 36 |
- |
|
| 37 |
-func tcget(fd uintptr, p *Termios) syscall.Errno {
|
|
| 38 |
- ret, err := C.tcgetattr(C.int(fd), (*C.struct_termios)(unsafe.Pointer(p))) |
|
| 39 |
- if ret != 0 {
|
|
| 40 |
- return err.(syscall.Errno) |
|
| 41 |
- } |
|
| 42 |
- return 0 |
|
| 43 |
-} |
|
| 44 |
- |
|
| 45 |
-func tcset(fd uintptr, p *Termios) syscall.Errno {
|
|
| 46 |
- ret, err := C.tcsetattr(C.int(fd), C.TCSANOW, (*C.struct_termios)(unsafe.Pointer(p))) |
|
| 47 |
- if ret != 0 {
|
|
| 48 |
- return err.(syscall.Errno) |
|
| 49 |
- } |
|
| 50 |
- return 0 |
|
| 51 |
-} |
| ... | ... |
@@ -1,6 +1,4 @@ |
| 1 | 1 |
// +build !windows |
| 2 |
-// +build !linux !cgo |
|
| 3 |
-// +build !linux !ppc64le |
|
| 4 | 2 |
// +build !solaris !cgo |
| 5 | 3 |
|
| 6 | 4 |
package term |
| ... | ... |
@@ -8,14 +6,16 @@ package term |
| 8 | 8 |
import ( |
| 9 | 9 |
"syscall" |
| 10 | 10 |
"unsafe" |
| 11 |
+ |
|
| 12 |
+ "golang.org/x/sys/unix" |
|
| 11 | 13 |
) |
| 12 | 14 |
|
| 13 | 15 |
func tcget(fd uintptr, p *Termios) syscall.Errno {
|
| 14 |
- _, _, err := syscall.Syscall(syscall.SYS_IOCTL, fd, uintptr(getTermios), uintptr(unsafe.Pointer(p))) |
|
| 16 |
+ _, _, err := unix.Syscall(unix.SYS_IOCTL, fd, uintptr(getTermios), uintptr(unsafe.Pointer(p))) |
|
| 15 | 17 |
return err |
| 16 | 18 |
} |
| 17 | 19 |
|
| 18 | 20 |
func tcset(fd uintptr, p *Termios) syscall.Errno {
|
| 19 |
- _, _, err := syscall.Syscall(syscall.SYS_IOCTL, fd, setTermios, uintptr(unsafe.Pointer(p))) |
|
| 21 |
+ _, _, err := unix.Syscall(unix.SYS_IOCTL, fd, setTermios, uintptr(unsafe.Pointer(p))) |
|
| 20 | 22 |
return err |
| 21 | 23 |
} |
| ... | ... |
@@ -5,6 +5,8 @@ package term |
| 5 | 5 |
import ( |
| 6 | 6 |
"syscall" |
| 7 | 7 |
"unsafe" |
| 8 |
+ |
|
| 9 |
+ "golang.org/x/sys/unix" |
|
| 8 | 10 |
) |
| 9 | 11 |
|
| 10 | 12 |
// #include <termios.h> |
| ... | ... |
@@ -13,7 +15,7 @@ import "C" |
| 13 | 13 |
// Termios is the Unix API for terminal I/O. |
| 14 | 14 |
// It is passthrough for syscall.Termios in order to make it portable with |
| 15 | 15 |
// other platforms where it is not available or handled differently. |
| 16 |
-type Termios syscall.Termios |
|
| 16 |
+type Termios unix.Termios |
|
| 17 | 17 |
|
| 18 | 18 |
// MakeRaw put the terminal connected to the given file descriptor into raw |
| 19 | 19 |
// mode and returns the previous state of the terminal so that it can be |
| ... | ... |
@@ -10,7 +10,8 @@ import ( |
| 10 | 10 |
"io" |
| 11 | 11 |
"os" |
| 12 | 12 |
"os/signal" |
| 13 |
- "syscall" |
|
| 13 |
+ |
|
| 14 |
+ "golang.org/x/sys/unix" |
|
| 14 | 15 |
) |
| 15 | 16 |
|
| 16 | 17 |
var ( |
| ... | ... |
@@ -79,7 +80,7 @@ func SaveState(fd uintptr) (*State, error) {
|
| 79 | 79 |
// descriptor, with echo disabled. |
| 80 | 80 |
func DisableEcho(fd uintptr, state *State) error {
|
| 81 | 81 |
newState := state.termios |
| 82 |
- newState.Lflag &^= syscall.ECHO |
|
| 82 |
+ newState.Lflag &^= unix.ECHO |
|
| 83 | 83 |
|
| 84 | 84 |
if err := tcset(fd, &newState); err != 0 {
|
| 85 | 85 |
return err |
| ... | ... |
@@ -3,8 +3,9 @@ |
| 3 | 3 |
package term |
| 4 | 4 |
|
| 5 | 5 |
import ( |
| 6 |
- "syscall" |
|
| 7 | 6 |
"unsafe" |
| 7 |
+ |
|
| 8 |
+ "golang.org/x/sys/unix" |
|
| 8 | 9 |
) |
| 9 | 10 |
|
| 10 | 11 |
/* |
| ... | ... |
@@ -22,7 +23,7 @@ import "C" |
| 22 | 22 |
// GetWinsize returns the window size based on the specified file descriptor. |
| 23 | 23 |
func GetWinsize(fd uintptr) (*Winsize, error) {
|
| 24 | 24 |
ws := &Winsize{}
|
| 25 |
- ret, err := C.my_ioctl(C.int(fd), C.int(syscall.TIOCGWINSZ), (*C.struct_winsize)(unsafe.Pointer(ws))) |
|
| 25 |
+ ret, err := C.my_ioctl(C.int(fd), C.int(unix.TIOCGWINSZ), (*C.struct_winsize)(unsafe.Pointer(ws))) |
|
| 26 | 26 |
// Skip retval = 0 |
| 27 | 27 |
if ret == 0 {
|
| 28 | 28 |
return ws, nil |
| ... | ... |
@@ -32,7 +33,7 @@ func GetWinsize(fd uintptr) (*Winsize, error) {
|
| 32 | 32 |
|
| 33 | 33 |
// SetWinsize tries to set the specified window size for the specified file descriptor. |
| 34 | 34 |
func SetWinsize(fd uintptr, ws *Winsize) error {
|
| 35 |
- ret, err := C.my_ioctl(C.int(fd), C.int(syscall.TIOCSWINSZ), (*C.struct_winsize)(unsafe.Pointer(ws))) |
|
| 35 |
+ ret, err := C.my_ioctl(C.int(fd), C.int(unix.TIOCSWINSZ), (*C.struct_winsize)(unsafe.Pointer(ws))) |
|
| 36 | 36 |
// Skip retval = 0 |
| 37 | 37 |
if ret == 0 {
|
| 38 | 38 |
return nil |
| ... | ... |
@@ -3,14 +3,15 @@ |
| 3 | 3 |
package term |
| 4 | 4 |
|
| 5 | 5 |
import ( |
| 6 |
- "syscall" |
|
| 7 | 6 |
"unsafe" |
| 7 |
+ |
|
| 8 |
+ "golang.org/x/sys/unix" |
|
| 8 | 9 |
) |
| 9 | 10 |
|
| 10 | 11 |
// GetWinsize returns the window size based on the specified file descriptor. |
| 11 | 12 |
func GetWinsize(fd uintptr) (*Winsize, error) {
|
| 12 | 13 |
ws := &Winsize{}
|
| 13 |
- _, _, err := syscall.Syscall(syscall.SYS_IOCTL, fd, uintptr(syscall.TIOCGWINSZ), uintptr(unsafe.Pointer(ws))) |
|
| 14 |
+ _, _, err := unix.Syscall(unix.SYS_IOCTL, fd, uintptr(unix.TIOCGWINSZ), uintptr(unsafe.Pointer(ws))) |
|
| 14 | 15 |
// Skipp errno = 0 |
| 15 | 16 |
if err == 0 {
|
| 16 | 17 |
return ws, nil |
| ... | ... |
@@ -20,7 +21,7 @@ func GetWinsize(fd uintptr) (*Winsize, error) {
|
| 20 | 20 |
|
| 21 | 21 |
// SetWinsize tries to set the specified window size for the specified file descriptor. |
| 22 | 22 |
func SetWinsize(fd uintptr, ws *Winsize) error {
|
| 23 |
- _, _, err := syscall.Syscall(syscall.SYS_IOCTL, fd, uintptr(syscall.TIOCSWINSZ), uintptr(unsafe.Pointer(ws))) |
|
| 23 |
+ _, _, err := unix.Syscall(unix.SYS_IOCTL, fd, uintptr(unix.TIOCSWINSZ), uintptr(unsafe.Pointer(ws))) |
|
| 24 | 24 |
// Skipp errno = 0 |
| 25 | 25 |
if err == 0 {
|
| 26 | 26 |
return nil |
| ... | ... |
@@ -6,10 +6,10 @@ import ( |
| 6 | 6 |
"io" |
| 7 | 7 |
"os" |
| 8 | 8 |
"os/signal" |
| 9 |
- "syscall" |
|
| 10 | 9 |
|
| 11 | 10 |
"github.com/Azure/go-ansiterm/winterm" |
| 12 | 11 |
"github.com/docker/docker/pkg/term/windows" |
| 12 |
+ "golang.org/x/sys/windows" |
|
| 13 | 13 |
) |
| 14 | 14 |
|
| 15 | 15 |
// State holds the console mode for the terminal. |
| ... | ... |
@@ -79,19 +79,19 @@ func StdStreams() (stdIn io.ReadCloser, stdOut, stdErr io.Writer) {
|
| 79 | 79 |
} |
| 80 | 80 |
|
| 81 | 81 |
if emulateStdin {
|
| 82 |
- stdIn = windows.NewAnsiReader(syscall.STD_INPUT_HANDLE) |
|
| 82 |
+ stdIn = windowsconsole.NewAnsiReader(windows.STD_INPUT_HANDLE) |
|
| 83 | 83 |
} else {
|
| 84 | 84 |
stdIn = os.Stdin |
| 85 | 85 |
} |
| 86 | 86 |
|
| 87 | 87 |
if emulateStdout {
|
| 88 |
- stdOut = windows.NewAnsiWriter(syscall.STD_OUTPUT_HANDLE) |
|
| 88 |
+ stdOut = windowsconsole.NewAnsiWriter(windows.STD_OUTPUT_HANDLE) |
|
| 89 | 89 |
} else {
|
| 90 | 90 |
stdOut = os.Stdout |
| 91 | 91 |
} |
| 92 | 92 |
|
| 93 | 93 |
if emulateStderr {
|
| 94 |
- stdErr = windows.NewAnsiWriter(syscall.STD_ERROR_HANDLE) |
|
| 94 |
+ stdErr = windowsconsole.NewAnsiWriter(windows.STD_ERROR_HANDLE) |
|
| 95 | 95 |
} else {
|
| 96 | 96 |
stdErr = os.Stderr |
| 97 | 97 |
} |
| ... | ... |
@@ -101,7 +101,7 @@ func StdStreams() (stdIn io.ReadCloser, stdOut, stdErr io.Writer) {
|
| 101 | 101 |
|
| 102 | 102 |
// GetFdInfo returns the file descriptor for an os.File and indicates whether the file represents a terminal. |
| 103 | 103 |
func GetFdInfo(in interface{}) (uintptr, bool) {
|
| 104 |
- return windows.GetHandleInfo(in) |
|
| 104 |
+ return windowsconsole.GetHandleInfo(in) |
|
| 105 | 105 |
} |
| 106 | 106 |
|
| 107 | 107 |
// GetWinsize returns the window size based on the specified file descriptor. |
| ... | ... |
@@ -121,7 +121,7 @@ func GetWinsize(fd uintptr) (*Winsize, error) {
|
| 121 | 121 |
|
| 122 | 122 |
// IsTerminal returns true if the given file descriptor is a terminal. |
| 123 | 123 |
func IsTerminal(fd uintptr) bool {
|
| 124 |
- return windows.IsConsole(fd) |
|
| 124 |
+ return windowsconsole.IsConsole(fd) |
|
| 125 | 125 |
} |
| 126 | 126 |
|
| 127 | 127 |
// RestoreTerminal restores the terminal connected to the given file descriptor |
| ... | ... |
@@ -1,35 +1,36 @@ |
| 1 | 1 |
package term |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 |
- "syscall" |
|
| 5 | 4 |
"unsafe" |
| 5 |
+ |
|
| 6 |
+ "golang.org/x/sys/unix" |
|
| 6 | 7 |
) |
| 7 | 8 |
|
| 8 | 9 |
const ( |
| 9 |
- getTermios = syscall.TIOCGETA |
|
| 10 |
- setTermios = syscall.TIOCSETA |
|
| 10 |
+ getTermios = unix.TIOCGETA |
|
| 11 |
+ setTermios = unix.TIOCSETA |
|
| 11 | 12 |
) |
| 12 | 13 |
|
| 13 |
-// Termios magic numbers, passthrough to the ones defined in syscall. |
|
| 14 |
+// Termios magic numbers, passthrough to the ones defined in unix. |
|
| 14 | 15 |
const ( |
| 15 |
- IGNBRK = syscall.IGNBRK |
|
| 16 |
- PARMRK = syscall.PARMRK |
|
| 17 |
- INLCR = syscall.INLCR |
|
| 18 |
- IGNCR = syscall.IGNCR |
|
| 19 |
- ECHONL = syscall.ECHONL |
|
| 20 |
- CSIZE = syscall.CSIZE |
|
| 21 |
- ICRNL = syscall.ICRNL |
|
| 22 |
- ISTRIP = syscall.ISTRIP |
|
| 23 |
- PARENB = syscall.PARENB |
|
| 24 |
- ECHO = syscall.ECHO |
|
| 25 |
- ICANON = syscall.ICANON |
|
| 26 |
- ISIG = syscall.ISIG |
|
| 27 |
- IXON = syscall.IXON |
|
| 28 |
- BRKINT = syscall.BRKINT |
|
| 29 |
- INPCK = syscall.INPCK |
|
| 30 |
- OPOST = syscall.OPOST |
|
| 31 |
- CS8 = syscall.CS8 |
|
| 32 |
- IEXTEN = syscall.IEXTEN |
|
| 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 |
|
| 33 | 34 |
) |
| 34 | 35 |
|
| 35 | 36 |
// Termios is the Unix API for terminal I/O. |
| ... | ... |
@@ -48,7 +49,7 @@ type Termios struct {
|
| 48 | 48 |
// restored. |
| 49 | 49 |
func MakeRaw(fd uintptr) (*State, error) {
|
| 50 | 50 |
var oldState State |
| 51 |
- if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, fd, uintptr(getTermios), uintptr(unsafe.Pointer(&oldState.termios))); err != 0 {
|
|
| 51 |
+ if _, _, err := unix.Syscall(unix.SYS_IOCTL, fd, uintptr(getTermios), uintptr(unsafe.Pointer(&oldState.termios))); err != 0 {
|
|
| 52 | 52 |
return nil, err |
| 53 | 53 |
} |
| 54 | 54 |
|
| ... | ... |
@@ -58,10 +59,10 @@ func MakeRaw(fd uintptr) (*State, error) {
|
| 58 | 58 |
newState.Lflag &^= (ECHO | ECHONL | ICANON | ISIG | IEXTEN) |
| 59 | 59 |
newState.Cflag &^= (CSIZE | PARENB) |
| 60 | 60 |
newState.Cflag |= CS8 |
| 61 |
- newState.Cc[syscall.VMIN] = 1 |
|
| 62 |
- newState.Cc[syscall.VTIME] = 0 |
|
| 61 |
+ newState.Cc[unix.VMIN] = 1 |
|
| 62 |
+ newState.Cc[unix.VTIME] = 0 |
|
| 63 | 63 |
|
| 64 |
- if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, fd, uintptr(setTermios), uintptr(unsafe.Pointer(&newState))); err != 0 {
|
|
| 64 |
+ if _, _, err := unix.Syscall(unix.SYS_IOCTL, fd, uintptr(setTermios), uintptr(unsafe.Pointer(&newState))); err != 0 {
|
|
| 65 | 65 |
return nil, err |
| 66 | 66 |
} |
| 67 | 67 |
|
| ... | ... |
@@ -1,35 +1,36 @@ |
| 1 | 1 |
package term |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 |
- "syscall" |
|
| 5 | 4 |
"unsafe" |
| 5 |
+ |
|
| 6 |
+ "golang.org/x/sys/unix" |
|
| 6 | 7 |
) |
| 7 | 8 |
|
| 8 | 9 |
const ( |
| 9 |
- getTermios = syscall.TIOCGETA |
|
| 10 |
- setTermios = syscall.TIOCSETA |
|
| 10 |
+ getTermios = unix.TIOCGETA |
|
| 11 |
+ setTermios = unix.TIOCSETA |
|
| 11 | 12 |
) |
| 12 | 13 |
|
| 13 |
-// Termios magic numbers, passthrough to the ones defined in syscall. |
|
| 14 |
+// Termios magic numbers, passthrough to the ones defined in unix. |
|
| 14 | 15 |
const ( |
| 15 |
- IGNBRK = syscall.IGNBRK |
|
| 16 |
- PARMRK = syscall.PARMRK |
|
| 17 |
- INLCR = syscall.INLCR |
|
| 18 |
- IGNCR = syscall.IGNCR |
|
| 19 |
- ECHONL = syscall.ECHONL |
|
| 20 |
- CSIZE = syscall.CSIZE |
|
| 21 |
- ICRNL = syscall.ICRNL |
|
| 22 |
- ISTRIP = syscall.ISTRIP |
|
| 23 |
- PARENB = syscall.PARENB |
|
| 24 |
- ECHO = syscall.ECHO |
|
| 25 |
- ICANON = syscall.ICANON |
|
| 26 |
- ISIG = syscall.ISIG |
|
| 27 |
- IXON = syscall.IXON |
|
| 28 |
- BRKINT = syscall.BRKINT |
|
| 29 |
- INPCK = syscall.INPCK |
|
| 30 |
- OPOST = syscall.OPOST |
|
| 31 |
- CS8 = syscall.CS8 |
|
| 32 |
- IEXTEN = syscall.IEXTEN |
|
| 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 |
|
| 33 | 34 |
) |
| 34 | 35 |
|
| 35 | 36 |
// Termios is the Unix API for terminal I/O. |
| ... | ... |
@@ -48,7 +49,7 @@ type Termios struct {
|
| 48 | 48 |
// restored. |
| 49 | 49 |
func MakeRaw(fd uintptr) (*State, error) {
|
| 50 | 50 |
var oldState State |
| 51 |
- if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, fd, uintptr(getTermios), uintptr(unsafe.Pointer(&oldState.termios))); err != 0 {
|
|
| 51 |
+ if _, _, err := unix.Syscall(unix.SYS_IOCTL, fd, uintptr(getTermios), uintptr(unsafe.Pointer(&oldState.termios))); err != 0 {
|
|
| 52 | 52 |
return nil, err |
| 53 | 53 |
} |
| 54 | 54 |
|
| ... | ... |
@@ -58,10 +59,10 @@ func MakeRaw(fd uintptr) (*State, error) {
|
| 58 | 58 |
newState.Lflag &^= (ECHO | ECHONL | ICANON | ISIG | IEXTEN) |
| 59 | 59 |
newState.Cflag &^= (CSIZE | PARENB) |
| 60 | 60 |
newState.Cflag |= CS8 |
| 61 |
- newState.Cc[syscall.VMIN] = 1 |
|
| 62 |
- newState.Cc[syscall.VTIME] = 0 |
|
| 61 |
+ newState.Cc[unix.VMIN] = 1 |
|
| 62 |
+ newState.Cc[unix.VTIME] = 0 |
|
| 63 | 63 |
|
| 64 |
- if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, fd, uintptr(setTermios), uintptr(unsafe.Pointer(&newState))); err != 0 {
|
|
| 64 |
+ if _, _, err := unix.Syscall(unix.SYS_IOCTL, fd, uintptr(setTermios), uintptr(unsafe.Pointer(&newState))); err != 0 {
|
|
| 65 | 65 |
return nil, err |
| 66 | 66 |
} |
| 67 | 67 |
|
| ... | ... |
@@ -1,15 +1,14 @@ |
| 1 |
-// +build !cgo |
|
| 2 |
- |
|
| 3 | 1 |
package term |
| 4 | 2 |
|
| 5 | 3 |
import ( |
| 6 |
- "syscall" |
|
| 7 | 4 |
"unsafe" |
| 5 |
+ |
|
| 6 |
+ "golang.org/x/sys/unix" |
|
| 8 | 7 |
) |
| 9 | 8 |
|
| 10 | 9 |
const ( |
| 11 |
- getTermios = syscall.TCGETS |
|
| 12 |
- setTermios = syscall.TCSETS |
|
| 10 |
+ getTermios = unix.TCGETS |
|
| 11 |
+ setTermios = unix.TCSETS |
|
| 13 | 12 |
) |
| 14 | 13 |
|
| 15 | 14 |
// Termios is the Unix API for terminal I/O. |
| ... | ... |
@@ -28,19 +27,19 @@ type Termios struct {
|
| 28 | 28 |
// restored. |
| 29 | 29 |
func MakeRaw(fd uintptr) (*State, error) {
|
| 30 | 30 |
var oldState State |
| 31 |
- if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, fd, getTermios, uintptr(unsafe.Pointer(&oldState.termios))); err != 0 {
|
|
| 31 |
+ if _, _, err := unix.Syscall(unix.SYS_IOCTL, fd, getTermios, uintptr(unsafe.Pointer(&oldState.termios))); err != 0 {
|
|
| 32 | 32 |
return nil, err |
| 33 | 33 |
} |
| 34 | 34 |
|
| 35 | 35 |
newState := oldState.termios |
| 36 | 36 |
|
| 37 |
- newState.Iflag &^= (syscall.IGNBRK | syscall.BRKINT | syscall.PARMRK | syscall.ISTRIP | syscall.INLCR | syscall.IGNCR | syscall.ICRNL | syscall.IXON) |
|
| 38 |
- newState.Oflag |= syscall.OPOST |
|
| 39 |
- newState.Lflag &^= (syscall.ECHO | syscall.ECHONL | syscall.ICANON | syscall.ISIG | syscall.IEXTEN) |
|
| 40 |
- newState.Cflag &^= (syscall.CSIZE | syscall.PARENB) |
|
| 41 |
- newState.Cflag |= syscall.CS8 |
|
| 37 |
+ newState.Iflag &^= (unix.IGNBRK | unix.BRKINT | unix.PARMRK | unix.ISTRIP | unix.INLCR | unix.IGNCR | unix.ICRNL | unix.IXON) |
|
| 38 |
+ newState.Oflag |= unix.OPOST |
|
| 39 |
+ newState.Lflag &^= (unix.ECHO | unix.ECHONL | unix.ICANON | unix.ISIG | unix.IEXTEN) |
|
| 40 |
+ newState.Cflag &^= (unix.CSIZE | unix.PARENB) |
|
| 41 |
+ newState.Cflag |= unix.CS8 |
|
| 42 | 42 |
|
| 43 |
- if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, fd, setTermios, uintptr(unsafe.Pointer(&newState))); err != 0 {
|
|
| 43 |
+ if _, _, err := unix.Syscall(unix.SYS_IOCTL, fd, setTermios, uintptr(unsafe.Pointer(&newState))); err != 0 {
|
|
| 44 | 44 |
return nil, err |
| 45 | 45 |
} |
| 46 | 46 |
return &oldState, nil |
| ... | ... |
@@ -1,35 +1,36 @@ |
| 1 | 1 |
package term |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 |
- "syscall" |
|
| 5 | 4 |
"unsafe" |
| 5 |
+ |
|
| 6 |
+ "golang.org/x/sys/unix" |
|
| 6 | 7 |
) |
| 7 | 8 |
|
| 8 | 9 |
const ( |
| 9 |
- getTermios = syscall.TIOCGETA |
|
| 10 |
- setTermios = syscall.TIOCSETA |
|
| 10 |
+ getTermios = unix.TIOCGETA |
|
| 11 |
+ setTermios = unix.TIOCSETA |
|
| 11 | 12 |
) |
| 12 | 13 |
|
| 13 |
-// Termios magic numbers, passthrough to the ones defined in syscall. |
|
| 14 |
+// Termios magic numbers, passthrough to the ones defined in unix. |
|
| 14 | 15 |
const ( |
| 15 |
- IGNBRK = syscall.IGNBRK |
|
| 16 |
- PARMRK = syscall.PARMRK |
|
| 17 |
- INLCR = syscall.INLCR |
|
| 18 |
- IGNCR = syscall.IGNCR |
|
| 19 |
- ECHONL = syscall.ECHONL |
|
| 20 |
- CSIZE = syscall.CSIZE |
|
| 21 |
- ICRNL = syscall.ICRNL |
|
| 22 |
- ISTRIP = syscall.ISTRIP |
|
| 23 |
- PARENB = syscall.PARENB |
|
| 24 |
- ECHO = syscall.ECHO |
|
| 25 |
- ICANON = syscall.ICANON |
|
| 26 |
- ISIG = syscall.ISIG |
|
| 27 |
- IXON = syscall.IXON |
|
| 28 |
- BRKINT = syscall.BRKINT |
|
| 29 |
- INPCK = syscall.INPCK |
|
| 30 |
- OPOST = syscall.OPOST |
|
| 31 |
- CS8 = syscall.CS8 |
|
| 32 |
- IEXTEN = syscall.IEXTEN |
|
| 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 |
|
| 33 | 34 |
) |
| 34 | 35 |
|
| 35 | 36 |
// Termios is the Unix API for terminal I/O. |
| ... | ... |
@@ -48,7 +49,7 @@ type Termios struct {
|
| 48 | 48 |
// restored. |
| 49 | 49 |
func MakeRaw(fd uintptr) (*State, error) {
|
| 50 | 50 |
var oldState State |
| 51 |
- if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, fd, uintptr(getTermios), uintptr(unsafe.Pointer(&oldState.termios))); err != 0 {
|
|
| 51 |
+ if _, _, err := unix.Syscall(unix.SYS_IOCTL, fd, uintptr(getTermios), uintptr(unsafe.Pointer(&oldState.termios))); err != 0 {
|
|
| 52 | 52 |
return nil, err |
| 53 | 53 |
} |
| 54 | 54 |
|
| ... | ... |
@@ -58,10 +59,10 @@ func MakeRaw(fd uintptr) (*State, error) {
|
| 58 | 58 |
newState.Lflag &^= (ECHO | ECHONL | ICANON | ISIG | IEXTEN) |
| 59 | 59 |
newState.Cflag &^= (CSIZE | PARENB) |
| 60 | 60 |
newState.Cflag |= CS8 |
| 61 |
- newState.Cc[syscall.VMIN] = 1 |
|
| 62 |
- newState.Cc[syscall.VTIME] = 0 |
|
| 61 |
+ newState.Cc[unix.VMIN] = 1 |
|
| 62 |
+ newState.Cc[unix.VTIME] = 0 |
|
| 63 | 63 |
|
| 64 |
- if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, fd, uintptr(setTermios), uintptr(unsafe.Pointer(&newState))); err != 0 {
|
|
| 64 |
+ if _, _, err := unix.Syscall(unix.SYS_IOCTL, fd, uintptr(setTermios), uintptr(unsafe.Pointer(&newState))); err != 0 {
|
|
| 65 | 65 |
return nil, err |
| 66 | 66 |
} |
| 67 | 67 |
|
| ... | ... |
@@ -2,7 +2,7 @@ |
| 2 | 2 |
// When asked for the set of standard streams (e.g., stdin, stdout, stderr), the code will create |
| 3 | 3 |
// and return pseudo-streams that convert ANSI sequences to / from Windows Console API calls. |
| 4 | 4 |
|
| 5 |
-package windows |
|
| 5 |
+package windowsconsole |
|
| 6 | 6 |
|
| 7 | 7 |
import ( |
| 8 | 8 |
"io/ioutil" |