瀏覽代碼

[pkg/term] Refactor BSD-specific files

Signed-off-by: Tibor Vass <tibor@docker.com>
Tibor Vass 8 年之前
父節點
當前提交
f8416e82d9
共有 5 個文件被更改,包括 43 次插入219 次删除
  1. 42 0
      pkg/term/termios_bsd.go
  2. 0 70
      pkg/term/termios_darwin.go
  3. 0 70
      pkg/term/termios_freebsd.go
  4. 1 9
      pkg/term/termios_linux.go
  5. 0 70
      pkg/term/termios_openbsd.go

+ 42 - 0
pkg/term/termios_bsd.go

@@ -0,0 +1,42 @@
+// +build darwin freebsd openbsd
+
+package term
+
+import (
+	"unsafe"
+
+	"golang.org/x/sys/unix"
+)
+
+const (
+	getTermios = unix.TIOCGETA
+	setTermios = unix.TIOCSETA
+)
+
+// Termios is the Unix API for terminal I/O.
+type Termios unix.Termios
+
+// MakeRaw put the terminal connected to the given file descriptor into raw
+// mode and returns the previous state of the terminal so that it can be
+// restored.
+func MakeRaw(fd uintptr) (*State, error) {
+	var oldState State
+	if _, _, err := unix.Syscall(unix.SYS_IOCTL, fd, getTermios, uintptr(unsafe.Pointer(&oldState.termios))); err != 0 {
+		return nil, err
+	}
+
+	newState := oldState.termios
+	newState.Iflag &^= (unix.IGNBRK | unix.BRKINT | unix.PARMRK | unix.ISTRIP | unix.INLCR | unix.IGNCR | unix.ICRNL | unix.IXON)
+	newState.Oflag &^= unix.OPOST
+	newState.Lflag &^= (unix.ECHO | unix.ECHONL | unix.ICANON | unix.ISIG | unix.IEXTEN)
+	newState.Cflag &^= (unix.CSIZE | unix.PARENB)
+	newState.Cflag |= unix.CS8
+	newState.Cc[unix.VMIN] = 1
+	newState.Cc[unix.VTIME] = 0
+
+	if _, _, err := unix.Syscall(unix.SYS_IOCTL, fd, setTermios, uintptr(unsafe.Pointer(&newState))); err != 0 {
+		return nil, err
+	}
+
+	return &oldState, nil
+}

+ 0 - 70
pkg/term/termios_darwin.go

@@ -1,70 +0,0 @@
-package term
-
-import (
-	"unsafe"
-
-	"golang.org/x/sys/unix"
-)
-
-const (
-	getTermios = unix.TIOCGETA
-	setTermios = unix.TIOCSETA
-)
-
-// Termios magic numbers, passthrough to the ones defined in unix.
-const (
-	IGNBRK = unix.IGNBRK
-	PARMRK = unix.PARMRK
-	INLCR  = unix.INLCR
-	IGNCR  = unix.IGNCR
-	ECHONL = unix.ECHONL
-	CSIZE  = unix.CSIZE
-	ICRNL  = unix.ICRNL
-	ISTRIP = unix.ISTRIP
-	PARENB = unix.PARENB
-	ECHO   = unix.ECHO
-	ICANON = unix.ICANON
-	ISIG   = unix.ISIG
-	IXON   = unix.IXON
-	BRKINT = unix.BRKINT
-	INPCK  = unix.INPCK
-	OPOST  = unix.OPOST
-	CS8    = unix.CS8
-	IEXTEN = unix.IEXTEN
-)
-
-// Termios is the Unix API for terminal I/O.
-type Termios struct {
-	Iflag  uint64
-	Oflag  uint64
-	Cflag  uint64
-	Lflag  uint64
-	Cc     [20]byte
-	Ispeed uint64
-	Ospeed uint64
-}
-
-// MakeRaw put the terminal connected to the given file descriptor into raw
-// mode and returns the previous state of the terminal so that it can be
-// restored.
-func MakeRaw(fd uintptr) (*State, error) {
-	var oldState State
-	if _, _, err := unix.Syscall(unix.SYS_IOCTL, fd, uintptr(getTermios), uintptr(unsafe.Pointer(&oldState.termios))); err != 0 {
-		return nil, err
-	}
-
-	newState := oldState.termios
-	newState.Iflag &^= (IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON)
-	newState.Oflag &^= OPOST
-	newState.Lflag &^= (ECHO | ECHONL | ICANON | ISIG | IEXTEN)
-	newState.Cflag &^= (CSIZE | PARENB)
-	newState.Cflag |= CS8
-	newState.Cc[unix.VMIN] = 1
-	newState.Cc[unix.VTIME] = 0
-
-	if _, _, err := unix.Syscall(unix.SYS_IOCTL, fd, uintptr(setTermios), uintptr(unsafe.Pointer(&newState))); err != 0 {
-		return nil, err
-	}
-
-	return &oldState, nil
-}

+ 0 - 70
pkg/term/termios_freebsd.go

@@ -1,70 +0,0 @@
-package term
-
-import (
-	"unsafe"
-
-	"golang.org/x/sys/unix"
-)
-
-const (
-	getTermios = unix.TIOCGETA
-	setTermios = unix.TIOCSETA
-)
-
-// Termios magic numbers, passthrough to the ones defined in unix.
-const (
-	IGNBRK = unix.IGNBRK
-	PARMRK = unix.PARMRK
-	INLCR  = unix.INLCR
-	IGNCR  = unix.IGNCR
-	ECHONL = unix.ECHONL
-	CSIZE  = unix.CSIZE
-	ICRNL  = unix.ICRNL
-	ISTRIP = unix.ISTRIP
-	PARENB = unix.PARENB
-	ECHO   = unix.ECHO
-	ICANON = unix.ICANON
-	ISIG   = unix.ISIG
-	IXON   = unix.IXON
-	BRKINT = unix.BRKINT
-	INPCK  = unix.INPCK
-	OPOST  = unix.OPOST
-	CS8    = unix.CS8
-	IEXTEN = unix.IEXTEN
-)
-
-// Termios is the Unix API for terminal I/O.
-type Termios struct {
-	Iflag  uint32
-	Oflag  uint32
-	Cflag  uint32
-	Lflag  uint32
-	Cc     [20]byte
-	Ispeed uint32
-	Ospeed uint32
-}
-
-// MakeRaw put the terminal connected to the given file descriptor into raw
-// mode and returns the previous state of the terminal so that it can be
-// restored.
-func MakeRaw(fd uintptr) (*State, error) {
-	var oldState State
-	if _, _, err := unix.Syscall(unix.SYS_IOCTL, fd, uintptr(getTermios), uintptr(unsafe.Pointer(&oldState.termios))); err != 0 {
-		return nil, err
-	}
-
-	newState := oldState.termios
-	newState.Iflag &^= (IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON)
-	newState.Oflag &^= OPOST
-	newState.Lflag &^= (ECHO | ECHONL | ICANON | ISIG | IEXTEN)
-	newState.Cflag &^= (CSIZE | PARENB)
-	newState.Cflag |= CS8
-	newState.Cc[unix.VMIN] = 1
-	newState.Cc[unix.VTIME] = 0
-
-	if _, _, err := unix.Syscall(unix.SYS_IOCTL, fd, uintptr(setTermios), uintptr(unsafe.Pointer(&newState))); err != 0 {
-		return nil, err
-	}
-
-	return &oldState, nil
-}

+ 1 - 9
pkg/term/termios_linux.go

@@ -12,15 +12,7 @@ const (
 )
 
 // Termios is the Unix API for terminal I/O.
-type Termios struct {
-	Iflag  uint32
-	Oflag  uint32
-	Cflag  uint32
-	Lflag  uint32
-	Cc     [20]byte
-	Ispeed uint32
-	Ospeed uint32
-}
+type Termios unix.Termios
 
 // MakeRaw put the terminal connected to the given file descriptor into raw
 // mode and returns the previous state of the terminal so that it can be

+ 0 - 70
pkg/term/termios_openbsd.go

@@ -1,70 +0,0 @@
-package term
-
-import (
-	"unsafe"
-
-	"golang.org/x/sys/unix"
-)
-
-const (
-	getTermios = unix.TIOCGETA
-	setTermios = unix.TIOCSETA
-)
-
-// Termios magic numbers, passthrough to the ones defined in unix.
-const (
-	IGNBRK = unix.IGNBRK
-	PARMRK = unix.PARMRK
-	INLCR  = unix.INLCR
-	IGNCR  = unix.IGNCR
-	ECHONL = unix.ECHONL
-	CSIZE  = unix.CSIZE
-	ICRNL  = unix.ICRNL
-	ISTRIP = unix.ISTRIP
-	PARENB = unix.PARENB
-	ECHO   = unix.ECHO
-	ICANON = unix.ICANON
-	ISIG   = unix.ISIG
-	IXON   = unix.IXON
-	BRKINT = unix.BRKINT
-	INPCK  = unix.INPCK
-	OPOST  = unix.OPOST
-	CS8    = unix.CS8
-	IEXTEN = unix.IEXTEN
-)
-
-// Termios is the Unix API for terminal I/O.
-type Termios struct {
-	Iflag  uint32
-	Oflag  uint32
-	Cflag  uint32
-	Lflag  uint32
-	Cc     [20]byte
-	Ispeed uint32
-	Ospeed uint32
-}
-
-// MakeRaw put the terminal connected to the given file descriptor into raw
-// mode and returns the previous state of the terminal so that it can be
-// restored.
-func MakeRaw(fd uintptr) (*State, error) {
-	var oldState State
-	if _, _, err := unix.Syscall(unix.SYS_IOCTL, fd, uintptr(getTermios), uintptr(unsafe.Pointer(&oldState.termios))); err != 0 {
-		return nil, err
-	}
-
-	newState := oldState.termios
-	newState.Iflag &^= (IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON)
-	newState.Oflag &^= OPOST
-	newState.Lflag &^= (ECHO | ECHONL | ICANON | ISIG | IEXTEN)
-	newState.Cflag &^= (CSIZE | PARENB)
-	newState.Cflag |= CS8
-	newState.Cc[unix.VMIN] = 1
-	newState.Cc[unix.VTIME] = 0
-
-	if _, _, err := unix.Syscall(unix.SYS_IOCTL, fd, uintptr(setTermios), uintptr(unsafe.Pointer(&newState))); err != 0 {
-		return nil, err
-	}
-
-	return &oldState, nil
-}