diff --git a/vendor.conf b/vendor.conf index 9c2916207..31af60d40 100644 --- a/vendor.conf +++ b/vendor.conf @@ -1,6 +1,6 @@ github.com/coreos/go-systemd 48702e0da86bd25e76cfef347e2adeb434a0d0a6 github.com/crosbymichael/go-runc 65847bfc51952703ca24b564d10de50d3f2db6e7 -github.com/crosbymichael/console f13f890e20a94bdec6c328cdf9410b7158f0cfa4 +github.com/crosbymichael/console 2a5cbd32a84cd1268c20c69bd090ec49e37009f8 github.com/crosbymichael/cgroups e950a27f3faf567abbf995bfbec90eaddc766d25 github.com/docker/go-metrics 8fd5772bf1584597834c6f7961a530f06cbfbb87 github.com/godbus/dbus c7fdd8b5cd55e87b4e1f4e372cdb1db61dd6c66f diff --git a/vendor/github.com/crosbymichael/console/console.go b/vendor/github.com/crosbymichael/console/console.go index a1d392cea..8be788b35 100644 --- a/vendor/github.com/crosbymichael/console/console.go +++ b/vendor/github.com/crosbymichael/console/console.go @@ -20,6 +20,8 @@ type Console interface { ResizeFrom(Console) error // SetRaw sets the console in raw mode SetRaw() error + // DisableEcho disables echo on the console + DisableEcho() error // Reset restores the console to its orignal state Reset() error // Size returns the window size of the console diff --git a/vendor/github.com/crosbymichael/console/console_linux.go b/vendor/github.com/crosbymichael/console/console_unix.go similarity index 75% rename from vendor/github.com/crosbymichael/console/console_linux.go rename to vendor/github.com/crosbymichael/console/console_unix.go index a259150b4..fb2701161 100644 --- a/vendor/github.com/crosbymichael/console/console_linux.go +++ b/vendor/github.com/crosbymichael/console/console_unix.go @@ -1,3 +1,5 @@ +// +build darwin freebsd linux + package console // #include @@ -34,8 +36,8 @@ func NewPty() (Console, string, error) { } type master struct { - f *os.File - termios *unix.Termios + f *os.File + original *unix.Termios } func (m *master) Read(b []byte) (int, error) { @@ -67,23 +69,42 @@ func (m *master) ResizeFrom(c Console) error { } func (m *master) Reset() error { - if m.termios == nil { + if m.original == nil { return nil } - return tcset(m.f.Fd(), m.termios) + return tcset(m.f.Fd(), m.original) +} + +func (m *master) getCurrent() (unix.Termios, error) { + var termios unix.Termios + if err := tcget(m.f.Fd(), &termios); err != nil { + return unix.Termios{}, err + } + if m.original == nil { + m.original = &termios + } + return termios, nil } func (m *master) SetRaw() error { - m.termios = &unix.Termios{} - if err := tcget(m.f.Fd(), m.termios); err != nil { + rawState, err := m.getCurrent() + if err != nil { return err } - rawState := *m.termios C.cfmakeraw((*C.struct_termios)(unsafe.Pointer(&rawState))) rawState.Oflag = rawState.Oflag | C.OPOST return tcset(m.f.Fd(), &rawState) } +func (m *master) DisableEcho() error { + rawState, err := m.getCurrent() + if err != nil { + return err + } + rawState.Lflag = rawState.Lflag &^ unix.ECHO + return tcset(m.f.Fd(), &rawState) +} + func (m *master) Size() (WinSize, error) { var ws WinSize if err := ioctl( diff --git a/vendor/github.com/crosbymichael/console/console_windows.go b/vendor/github.com/crosbymichael/console/console_windows.go index 0dcefff03..8d133eab4 100644 --- a/vendor/github.com/crosbymichael/console/console_windows.go +++ b/vendor/github.com/crosbymichael/console/console_windows.go @@ -126,6 +126,18 @@ func (m *master) ResizeFrom(c Console) error { return ErrNotImplemented } +func (m *master) DisableEcho() error { + mode := m.inMode &^ winterm.ENABLE_ECHO_INPUT + mode |= winterm.ENABLE_PROCESSED_INPUT + mode |= winterm.ENABLE_LINE_INPUT + + if err := winterm.SetConsoleMode(m.in, mode); err != nil { + return errors.Wrap(err, "unable to set console to disable echo") + } + + return nil +} + func (m *master) Close() error { return nil } diff --git a/vendor/github.com/crosbymichael/console/tc_darwin.go b/vendor/github.com/crosbymichael/console/tc_darwin.go new file mode 100644 index 000000000..d86c315da --- /dev/null +++ b/vendor/github.com/crosbymichael/console/tc_darwin.go @@ -0,0 +1,51 @@ +package console + +import ( + "fmt" + "os" + "unsafe" + + "golang.org/x/sys/unix" +) + +func tcget(fd uintptr, p *unix.Termios) error { + return ioctl(fd, unix.TIOCGETA, uintptr(unsafe.Pointer(p))) +} + +func tcset(fd uintptr, p *unix.Termios) error { + return ioctl(fd, unix.TIOCSETA, uintptr(unsafe.Pointer(p))) +} + +func ioctl(fd, flag, data uintptr) error { + if _, _, err := unix.Syscall(unix.SYS_IOCTL, fd, flag, data); err != 0 { + return err + } + return nil +} + +// unlockpt unlocks the slave pseudoterminal device corresponding to the master pseudoterminal referred to by f. +// unlockpt should be called before opening the slave side of a pty. +func unlockpt(f *os.File) error { + var u int32 + return ioctl(f.Fd(), unix.TIOCPTYUNLK, uintptr(unsafe.Pointer(&u))) +} + +// ptsname retrieves the name of the first available pts for the given master. +func ptsname(f *os.File) (string, error) { + var n int32 + if err := ioctl(f.Fd(), unix.TIOCPTYGNAME, uintptr(unsafe.Pointer(&n))); err != nil { + return "", err + } + return fmt.Sprintf("/dev/pts/%d", n), nil +} + +func saneTerminal(f *os.File) error { + // Go doesn't have a wrapper for any of the termios ioctls. + var termios unix.Termios + if err := tcget(f.Fd(), &termios); err != nil { + return err + } + // Set -onlcr so we don't have to deal with \r. + termios.Oflag &^= unix.ONLCR + return tcset(f.Fd(), &termios) +} diff --git a/vendor/github.com/crosbymichael/console/tc_freebsd.go b/vendor/github.com/crosbymichael/console/tc_freebsd.go new file mode 100644 index 000000000..478f60ac9 --- /dev/null +++ b/vendor/github.com/crosbymichael/console/tc_freebsd.go @@ -0,0 +1,51 @@ +package console + +import ( + "fmt" + "os" + "unsafe" + + "golang.org/x/sys/unix" +) + +func tcget(fd uintptr, p *unix.Termios) error { + return ioctl(fd, unix.TIOCGETA, uintptr(unsafe.Pointer(p))) +} + +func tcset(fd uintptr, p *unix.Termios) error { + return ioctl(fd, unix.TIOCSETA, uintptr(unsafe.Pointer(p))) +} + +func ioctl(fd, flag, data uintptr) error { + if _, _, err := unix.Syscall(unix.SYS_IOCTL, fd, flag, data); err != 0 { + return err + } + return nil +} + +// unlockpt unlocks the slave pseudoterminal device corresponding to the master pseudoterminal referred to by f. +// unlockpt should be called before opening the slave side of a pty. +// This does not exist on FreeBSD, it does not allocate controlling terminals on open +func unlockpt(f *os.File) error { + return nil +} + +// ptsname retrieves the name of the first available pts for the given master. +func ptsname(f *os.File) (string, error) { + var n int32 + if err := ioctl(f.Fd(), unix.TIOCGPTN, uintptr(unsafe.Pointer(&n))); err != nil { + return "", err + } + return fmt.Sprintf("/dev/pts/%d", n), nil +} + +func saneTerminal(f *os.File) error { + // Go doesn't have a wrapper for any of the termios ioctls. + var termios unix.Termios + if err := tcget(f.Fd(), &termios); err != nil { + return err + } + // Set -onlcr so we don't have to deal with \r. + termios.Oflag &^= unix.ONLCR + return tcset(f.Fd(), &termios) +} diff --git a/vendor/github.com/crosbymichael/console/tc.go b/vendor/github.com/crosbymichael/console/tc_linux.go similarity index 98% rename from vendor/github.com/crosbymichael/console/tc.go rename to vendor/github.com/crosbymichael/console/tc_linux.go index 260396bef..67c89f067 100644 --- a/vendor/github.com/crosbymichael/console/tc.go +++ b/vendor/github.com/crosbymichael/console/tc_linux.go @@ -1,5 +1,3 @@ -// +build linux - package console import (