Update console vendor
Signed-off-by: Derek McGowan <derek@mcgstyle.net>
This commit is contained in:
parent
b3640fdc8c
commit
427468c626
@ -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
|
||||
|
2
vendor/github.com/crosbymichael/console/console.go
generated
vendored
2
vendor/github.com/crosbymichael/console/console.go
generated
vendored
@ -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
|
||||
|
@ -1,3 +1,5 @@
|
||||
// +build darwin freebsd linux
|
||||
|
||||
package console
|
||||
|
||||
// #include <termios.h>
|
||||
@ -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(
|
12
vendor/github.com/crosbymichael/console/console_windows.go
generated
vendored
12
vendor/github.com/crosbymichael/console/console_windows.go
generated
vendored
@ -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
|
||||
}
|
||||
|
51
vendor/github.com/crosbymichael/console/tc_darwin.go
generated
vendored
Normal file
51
vendor/github.com/crosbymichael/console/tc_darwin.go
generated
vendored
Normal file
@ -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)
|
||||
}
|
51
vendor/github.com/crosbymichael/console/tc_freebsd.go
generated
vendored
Normal file
51
vendor/github.com/crosbymichael/console/tc_freebsd.go
generated
vendored
Normal file
@ -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)
|
||||
}
|
@ -1,5 +1,3 @@
|
||||
// +build linux
|
||||
|
||||
package console
|
||||
|
||||
import (
|
Loading…
Reference in New Issue
Block a user