mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
[pkg/term] use IoctlGetTermios/IoctlSetTermios from x/sys/unix
Use IoctlGetTermios/IoctlSetTermios from golang.org/x/sys/unix instead of manually reimplementing them. Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
This commit is contained in:
parent
6c9d715a8c
commit
6476504695
1 changed files with 10 additions and 11 deletions
|
@ -1,8 +1,6 @@
|
|||
package term
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
|
@ -18,20 +16,21 @@ type Termios unix.Termios
|
|||
// 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 {
|
||||
termios, err := unix.IoctlGetTermios(int(fd), getTermios)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
newState := oldState.termios
|
||||
var oldState State
|
||||
oldState.termios = Termios(*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
|
||||
termios.Iflag &^= (unix.IGNBRK | unix.BRKINT | unix.PARMRK | unix.ISTRIP | unix.INLCR | unix.IGNCR | unix.ICRNL | unix.IXON)
|
||||
termios.Oflag &^= unix.OPOST
|
||||
termios.Lflag &^= (unix.ECHO | unix.ECHONL | unix.ICANON | unix.ISIG | unix.IEXTEN)
|
||||
termios.Cflag &^= (unix.CSIZE | unix.PARENB)
|
||||
termios.Cflag |= unix.CS8
|
||||
|
||||
if _, _, err := unix.Syscall(unix.SYS_IOCTL, fd, setTermios, uintptr(unsafe.Pointer(&newState))); err != 0 {
|
||||
if err := unix.IoctlSetTermios(int(fd), setTermios, termios); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &oldState, nil
|
||||
|
|
Loading…
Add table
Reference in a new issue