diff --git a/cmd/lscp/args.go b/cmd/lscp/args.go index c4b6634b..c8075912 100644 --- a/cmd/lscp/args.go +++ b/cmd/lscp/args.go @@ -60,7 +60,7 @@ USAGE: app.Name = "lscp" app.Usage = "TUI list select and parallel scp client command." app.Copyright = "blacknon(blacknon@orebibou.com)" - app.Version = "0.6.5" + app.Version = "0.6.6" // options // TODO(blacknon): オプションの追加(0.7.0) diff --git a/cmd/lsftp/args.go b/cmd/lsftp/args.go index 4cb104ae..f25ac482 100644 --- a/cmd/lsftp/args.go +++ b/cmd/lsftp/args.go @@ -51,7 +51,7 @@ USAGE: app.Name = "lsftp" app.Usage = "TUI list select and parallel sftp client command." app.Copyright = "blacknon(blacknon@orebibou.com)" - app.Version = "0.6.5" + app.Version = "0.6.6" app.Flags = []cli.Flag{ cli.StringFlag{Name: "file,F", Value: defConf, Usage: "config file path"}, diff --git a/cmd/lssh/args.go b/cmd/lssh/args.go index 63bafee4..2f0e7f24 100644 --- a/cmd/lssh/args.go +++ b/cmd/lssh/args.go @@ -65,7 +65,7 @@ USAGE: app.Name = "lssh" app.Usage = "TUI list select and parallel ssh client command." app.Copyright = "blacknon(blacknon@orebibou.com)" - app.Version = "0.6.5" + app.Version = "0.6.6" // TODO(blacknon): オプションの追加 // -f ... バックグラウンドでの接続(X11接続やport forwardingをバックグラウンドで実行する場合など)。 diff --git a/go.mod b/go.mod index 5b141581..0145a1d9 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ require ( github.com/BurntSushi/toml v0.3.1 github.com/blacknon/go-sshlib v0.1.5 github.com/blacknon/textcol v0.0.1 - github.com/c-bata/go-prompt v0.2.6 + github.com/c-bata/go-prompt v0.2.5 github.com/dustin/go-humanize v1.0.0 github.com/kevinburke/ssh_config v0.0.0-20190724205821-6cfae18c12b8 github.com/mattn/go-runewidth v0.0.13 @@ -36,7 +36,7 @@ require ( github.com/mattn/go-tty v0.0.3 // indirect github.com/miekg/pkcs11 v1.1.1 // indirect github.com/pkg/errors v0.9.1 // indirect - github.com/pkg/term v1.2.0-beta.2 // indirect + github.com/pkg/term v1.1.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/rivo/uniseg v0.2.0 // indirect github.com/thales-e-security/pool v0.0.2 // indirect diff --git a/go.sum b/go.sum index feb905d7..5dcc7d40 100644 --- a/go.sum +++ b/go.sum @@ -14,8 +14,8 @@ github.com/blacknon/go-sshlib v0.1.5 h1:nHuIi022DS72kf5/WTBRE15NHW43Qb+1umM76Gms github.com/blacknon/go-sshlib v0.1.5/go.mod h1:sgMpYTYseacjT4Bt9pPwjMd+eMXsLGCjDtoFugXKYDE= github.com/blacknon/textcol v0.0.1 h1:x9h7yLPGyr8Pdz12XJ30h7Iz5mJlKd0CzfGYxhrmnk8= github.com/blacknon/textcol v0.0.1/go.mod h1:1x1tHA4cEgiQ8BsKysc60OALSZMG9WjmbjmJvPqIInQ= -github.com/c-bata/go-prompt v0.2.6 h1:POP+nrHE+DfLYx370bedwNhsqmpCUynWPxuHi0C5vZI= -github.com/c-bata/go-prompt v0.2.6/go.mod h1:/LMAke8wD2FsNu9EXNdHxNLbd9MedkPnCdfpU9wwHfY= +github.com/c-bata/go-prompt v0.2.5 h1:3zg6PecEywxNn0xiqcXHD96fkbxghD+gdB2tbsYfl+Y= +github.com/c-bata/go-prompt v0.2.5/go.mod h1:vFnjEGDIIA/Lib7giyE4E9c50Lvl8j0S+7FVlAwDAVw= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/dchest/bcrypt_pbkdf v0.0.0-20150205184540-83f37f9c154a h1:saTgr5tMLFnmy/yg3qDTft4rE5DY2uJ/cCxCe3q0XTU= @@ -58,8 +58,8 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/sftp v1.10.1 h1:VasscCm72135zRysgrJDKsntdmPN+OuU3+nnHYA9wyc= github.com/pkg/sftp v1.10.1/go.mod h1:lYOWFsE0bwd1+KfKJaKeuokY15vzFx25BLbzYYoAxZI= -github.com/pkg/term v1.2.0-beta.2 h1:L3y/h2jkuBVFdWiJvNfYfKmzcCnILw7mJWm2JQuMppw= -github.com/pkg/term v1.2.0-beta.2/go.mod h1:E25nymQcrSllhX42Ok8MRm1+hyBdHY0dCeiKZ9jpNGw= +github.com/pkg/term v1.1.0 h1:xIAAdCMh3QIAy+5FrE8Ad8XoDhEU4ufwbaSozViP9kk= +github.com/pkg/term v1.1.0/go.mod h1:E25nymQcrSllhX42Ok8MRm1+hyBdHY0dCeiKZ9jpNGw= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY= diff --git a/output/output.go b/output/output.go index 893e3014..0b436d45 100644 --- a/output/output.go +++ b/output/output.go @@ -221,34 +221,32 @@ func OutColorStrings(num int, inStrings string) (str string) { // PushInput is Reader([io.PipeReader, os.Stdin]) to []io.WriteCloser. func PushInput(isExit <-chan bool, output []io.WriteCloser, input io.Reader) { rd := bufio.NewReader(input) + loop: for { buf := make([]byte, 1024) size, err := rd.Read(buf) - if size > 0 { - d := buf[:size] + select { + case <-isExit: + break loop + case <-time.After(10 * time.Millisecond): + if size > 0 { + d := buf[:size] - // write - for _, w := range output { - w.Write(d) + // write + for _, w := range output { + w.Write(d) + } } - } - if input != os.Stdin { - switch err { - case nil: - continue - case io.ErrClosedPipe, io.EOF: - break loop + if input != os.Stdin { + switch err { + case io.ErrClosedPipe, io.EOF: + break loop + } } - } - select { - case <-isExit: - break loop - case <-time.After(10 * time.Millisecond): - continue } } diff --git a/ssh/pshell_cmd.go b/ssh/pshell_cmd.go index 39cb3ff1..97330f00 100644 --- a/ssh/pshell_cmd.go +++ b/ssh/pshell_cmd.go @@ -297,17 +297,7 @@ func (ps *pShell) executeRemotePipeLine(pline pipeLine, in *io.PipeReader, out * } // multi input-writer - switch stdin.(type) { - case *os.File: - // push input to pararell session - // (Only when input is os.Stdin and output is os.Stdout). - if stdout == os.Stdout { - // go output.PushInput(exitInput, writers, byte('\n')) - go output.PushInput(exitInput, writers, stdin) - } - case *io.PipeReader: - go output.PushInput(exitInput, writers, stdin) - } + go output.PushInput(exitInput, writers, stdin) // run command for _, s := range sessions { @@ -336,14 +326,14 @@ func (ps *pShell) executeRemotePipeLine(pline pipeLine, in *io.PipeReader, out * // wait ps.wait(len(sessions), exit) - // wait time (0.500 sec) + // wait time (0.050 sec) time.Sleep(500 * time.Millisecond) // send exit ch <- true // exit input. - if stdin == os.Stdin && stdout == os.Stdout { + if stdin == os.Stdin { exitInput <- true } @@ -353,6 +343,9 @@ func (ps *pShell) executeRemotePipeLine(pline pipeLine, in *io.PipeReader, out * out.CloseWithError(io.ErrClosedPipe) } + // wait time (0.050 sec) + time.Sleep(500 * time.Millisecond) + return } diff --git a/vendor/github.com/c-bata/go-prompt/README.md b/vendor/github.com/c-bata/go-prompt/README.md index cfcd7a39..e3b34723 100644 --- a/vendor/github.com/c-bata/go-prompt/README.md +++ b/vendor/github.com/c-bata/go-prompt/README.md @@ -51,8 +51,6 @@ func main() { * [docker-slim/docker-slim: Don't change anything in your Docker container image and minify it by up to 30x (and for compiled languages even more) making it secure too! (free and open source)](https://github.com/docker-slim/docker-slim) * [rueyaa332266/ezcron: Ezcron is a CLI tool, helping you deal with cron expression easier.](https://github.com/rueyaa332266/ezcron) * [qingstor/qsctl: Advanced command line tool for QingStor Object Storage.](https://github.com/qingstor/qsctl) -* [segmentio/topicctl: Tool for declarative management of Kafka topics](https://github.com/segmentio/topicctl) -* [chriswalz/bit: Bit is a modern Git CLI](https://github.com/chriswalz/bit) * (If you create a CLI utility using go-prompt and want your own project to be listed here, please submit a GitHub issue.) ## Features diff --git a/vendor/github.com/c-bata/go-prompt/internal/term/raw.go b/vendor/github.com/c-bata/go-prompt/internal/term/raw.go index 7aa3ed8d..e2a4a7b8 100644 --- a/vendor/github.com/c-bata/go-prompt/internal/term/raw.go +++ b/vendor/github.com/c-bata/go-prompt/internal/term/raw.go @@ -25,5 +25,5 @@ func SetRaw(fd int) error { n.Cc[syscall.VMIN] = 1 n.Cc[syscall.VTIME] = 0 - return termios.Tcsetattr(uintptr(fd), termios.TCSANOW, (*unix.Termios)(n)) + return termios.Tcsetattr(uintptr(fd), termios.TCSANOW, (*unix.Termios)(&n)) } diff --git a/vendor/github.com/c-bata/go-prompt/internal/term/term.go b/vendor/github.com/c-bata/go-prompt/internal/term/term.go index 3f3a53c0..f6dc3cd4 100644 --- a/vendor/github.com/c-bata/go-prompt/internal/term/term.go +++ b/vendor/github.com/c-bata/go-prompt/internal/term/term.go @@ -10,16 +10,16 @@ import ( ) var ( - saveTermios *unix.Termios + saveTermios unix.Termios saveTermiosFD int saveTermiosOnce sync.Once ) -func getOriginalTermios(fd int) (*unix.Termios, error) { +func getOriginalTermios(fd int) (unix.Termios, error) { var err error saveTermiosOnce.Do(func() { saveTermiosFD = fd - saveTermios, err = termios.Tcgetattr(uintptr(fd)) + err = termios.Tcgetattr(uintptr(fd), &saveTermios) }) return saveTermios, err } @@ -30,5 +30,5 @@ func Restore() error { if err != nil { return err } - return termios.Tcsetattr(uintptr(saveTermiosFD), termios.TCSANOW, o) + return termios.Tcsetattr(uintptr(saveTermiosFD), termios.TCSANOW, &o) } diff --git a/vendor/github.com/pkg/term/termios/ioctl.go b/vendor/github.com/pkg/term/termios/ioctl.go index 10aa2b13..ce37d78f 100644 --- a/vendor/github.com/pkg/term/termios/ioctl.go +++ b/vendor/github.com/pkg/term/termios/ioctl.go @@ -1,9 +1,16 @@ -// +build !windows +// +build !windows,!solaris package termios -import "golang.org/x/sys/unix" +import ( + "syscall" + + "golang.org/x/sys/unix" +) func ioctl(fd, request, argp uintptr) error { - return unix.IoctlSetInt(int(fd), uint(request), int(argp)) + if _, _, e := unix.Syscall6(syscall.SYS_IOCTL, fd, request, argp, 0, 0, 0); e != 0 { + return e + } + return nil } diff --git a/vendor/github.com/pkg/term/termios/ioctl_darwin.go b/vendor/github.com/pkg/term/termios/ioctl_darwin.go new file mode 100644 index 00000000..5d9b91ab --- /dev/null +++ b/vendor/github.com/pkg/term/termios/ioctl_darwin.go @@ -0,0 +1,10 @@ +package termios + +const ( + _IOC_PARAM_SHIFT = 13 + _IOC_PARAM_MASK = (1 << _IOC_PARAM_SHIFT) - 1 +) + +func _IOC_PARM_LEN(ioctl uintptr) uintptr { + return (ioctl >> 16) & _IOC_PARAM_MASK +} diff --git a/vendor/github.com/pkg/term/termios/ioctl_solaris.go b/vendor/github.com/pkg/term/termios/ioctl_solaris.go new file mode 100644 index 00000000..95c40ea8 --- /dev/null +++ b/vendor/github.com/pkg/term/termios/ioctl_solaris.go @@ -0,0 +1,7 @@ +package termios + +import "golang.org/x/sys/unix" + +func ioctl(fd, request, argp uintptr) error { + return unix.IoctlSetInt(int(fd), uint(request), int(argp)) +} diff --git a/vendor/github.com/pkg/term/termios/pty_cgo.go b/vendor/github.com/pkg/term/termios/pty_bsd.go similarity index 94% rename from vendor/github.com/pkg/term/termios/pty_cgo.go rename to vendor/github.com/pkg/term/termios/pty_bsd.go index 568f9cf5..45336d41 100644 --- a/vendor/github.com/pkg/term/termios/pty_cgo.go +++ b/vendor/github.com/pkg/term/termios/pty_bsd.go @@ -1,4 +1,4 @@ -// +build dragonfly openbsd solaris +// +build dragonfly openbsd package termios diff --git a/vendor/github.com/pkg/term/termios/pty_darwin.go b/vendor/github.com/pkg/term/termios/pty_darwin.go index a57357a9..9377112b 100644 --- a/vendor/github.com/pkg/term/termios/pty_darwin.go +++ b/vendor/github.com/pkg/term/termios/pty_darwin.go @@ -11,15 +11,6 @@ func open_pty_master() (uintptr, error) { return open_device("/dev/ptmx") } -const ( - _IOC_PARAM_SHIFT = 13 - _IOC_PARAM_MASK = (1 << _IOC_PARAM_SHIFT) - 1 -) - -func _IOC_PARM_LEN(ioctl uintptr) uintptr { - return (ioctl >> 16) & _IOC_PARAM_MASK -} - func Ptsname(fd uintptr) (string, error) { n := make([]byte, _IOC_PARM_LEN(unix.TIOCPTYGNAME)) diff --git a/vendor/github.com/pkg/term/termios/pty_freebsd.go b/vendor/github.com/pkg/term/termios/pty_freebsd.go index f7bf882b..d449fbf4 100644 --- a/vendor/github.com/pkg/term/termios/pty_freebsd.go +++ b/vendor/github.com/pkg/term/termios/pty_freebsd.go @@ -2,8 +2,7 @@ package termios import ( "fmt" - - "golang.org/x/sys/unix" + "unsafe" ) func posix_openpt(oflag int) (fd uintptr, err error) { @@ -21,12 +20,17 @@ func open_pty_master() (uintptr, error) { } func Ptsname(fd uintptr) (string, error) { - n, err := unix.IoctlGetInt(int(fd), unix.TIOCGPTN) - return fmt.Sprintf("/dev/pts/%d", n), err + var n uintptr + err := ioctl(fd, unix.TIOCGPTN, uintptr(unsafe.Pointer(&n))) + if err != nil { + return "", err + } + return fmt.Sprintf("/dev/pts/%d", n), nil } func grantpt(fd uintptr) error { - return unix.IoctlSetInt(int(fd), unix.TIOCGPTN, 0) + var n uintptr + return ioctl(fd, unix.TIOCGPTN, uintptr(unsafe.Pointer(&n))) } func unlockpt(fd uintptr) error { diff --git a/vendor/github.com/pkg/term/termios/pty_linux.go b/vendor/github.com/pkg/term/termios/pty_linux.go index 018511c1..fc9954ef 100644 --- a/vendor/github.com/pkg/term/termios/pty_linux.go +++ b/vendor/github.com/pkg/term/termios/pty_linux.go @@ -12,8 +12,12 @@ func open_pty_master() (uintptr, error) { } func Ptsname(fd uintptr) (string, error) { - n, err := unix.IoctlGetInt(int(fd), unix.TIOCGPTN) - return fmt.Sprintf("/dev/pts/%d", n), err + var n uintptr + err := ioctl(fd, unix.TIOCGPTN, uintptr(unsafe.Pointer(&n))) + if err != nil { + return "", err + } + return fmt.Sprintf("/dev/pts/%d", n), nil } func grantpt(fd uintptr) error { diff --git a/vendor/github.com/pkg/term/termios/pty_netbsd.go b/vendor/github.com/pkg/term/termios/pty_netbsd.go index c921017b..a40e7f9a 100644 --- a/vendor/github.com/pkg/term/termios/pty_netbsd.go +++ b/vendor/github.com/pkg/term/termios/pty_netbsd.go @@ -7,7 +7,11 @@ import ( ) func open_pty_master() (uintptr, error) { - return open_device("/dev/ptmx") + fd, err := unix.Open("/dev/ptmx", unix.O_NOCTTY|unix.O_RDWR, 0666) + if err != nil { + return 0, err + } + return uintptr(fd), nil } func Ptsname(fd uintptr) (string, error) { diff --git a/vendor/github.com/pkg/term/termios/pty_solaris.go b/vendor/github.com/pkg/term/termios/pty_solaris.go new file mode 100644 index 00000000..6fccd1ee --- /dev/null +++ b/vendor/github.com/pkg/term/termios/pty_solaris.go @@ -0,0 +1,33 @@ +package termios + +// #include +import "C" + +import "syscall" + +func open_pty_master() (uintptr, error) { + return open_device("/dev/ptmx") +} + +func Ptsname(fd uintptr) (string, error) { + slavename := C.GoString(C.ptsname(C.int(fd))) + return slavename, nil +} + +func grantpt(fd uintptr) error { + rc := C.grantpt(C.int(fd)) + if rc == 0 { + return nil + } else { + return syscall.Errno(rc) + } +} + +func unlockpt(fd uintptr) error { + rc := C.unlockpt(C.int(fd)) + if rc == 0 { + return nil + } else { + return syscall.Errno(rc) + } +} diff --git a/vendor/github.com/pkg/term/termios/termios.go b/vendor/github.com/pkg/term/termios/termios.go index 8ef8ea2c..a69c1f0d 100644 --- a/vendor/github.com/pkg/term/termios/termios.go +++ b/vendor/github.com/pkg/term/termios/termios.go @@ -26,11 +26,6 @@ func Tiocmbic(fd uintptr, status int) error { return unix.IoctlSetPointerInt(int(fd), unix.TIOCMBIC, status) } -// Tiocoutq return the number of bytes in the output buffer. -func Tiocoutq(fd uintptr) (int, error) { - return unix.IoctlGetInt(int(fd), unix.TIOCOUTQ) -} - // Cfmakecbreak modifies attr for cbreak mode. func Cfmakecbreak(attr *unix.Termios) { attr.Lflag &^= unix.ECHO | unix.ICANON diff --git a/vendor/github.com/pkg/term/termios/termios_bsd.go b/vendor/github.com/pkg/term/termios/termios_bsd.go index 86221c20..f433f375 100644 --- a/vendor/github.com/pkg/term/termios/termios_bsd.go +++ b/vendor/github.com/pkg/term/termios/termios_bsd.go @@ -9,6 +9,9 @@ import ( ) const ( + FREAD = 0x0001 + FWRITE = 0x0002 + IXON = 0x00000200 IXOFF = 0x00000400 IXANY = 0x00000800 @@ -18,8 +21,8 @@ const ( ) // Tcgetattr gets the current serial port settings. -func Tcgetattr(fd uintptr) (*unix.Termios, error) { - return unix.IoctlGetTermios(int(fd), unix.TIOCGETA) +func Tcgetattr(fd uintptr, argp *unix.Termios) error { + return unix.IoctlSetTermios(int(fd), unix.TIOCGETA, argp) } // Tcsetattr sets the current serial port settings. @@ -40,7 +43,7 @@ func Tcsetattr(fd, opt uintptr, argp *unix.Termios) error { // Tcsendbreak function transmits a continuous stream of zero-valued bits for // four-tenths of a second to the terminal referenced by fildes. The duration // parameter is ignored in this implementation. -func Tcsendbreak(fd uintptr, duration int) error { +func Tcsendbreak(fd, duration uintptr) error { if err := unix.IoctlSetInt(int(fd), unix.TIOCSBRK, 0); err != nil { return err } @@ -55,7 +58,18 @@ func Tcdrain(fd uintptr) error { // Tcflush discards data written to the object referred to by fd but not transmitted, or data received but not read, depending on the value of which. func Tcflush(fd, which uintptr) error { - return unix.IoctlSetPointerInt(int(fd), unix.TIOCFLUSH, int(which)) + var com int + switch which { + case unix.TCIFLUSH: + com = FREAD + case unix.TCOFLUSH: + com = FWRITE + case unix.TCIOFLUSH: + com = FREAD | FWRITE + default: + return unix.EINVAL + } + return unix.IoctlSetPointerInt(int(fd), unix.TIOCFLUSH, com) } // Cfgetispeed returns the input baud rate stored in the termios structure. @@ -68,3 +82,8 @@ func Cfgetospeed(attr *unix.Termios) uint32 { return uint32(attr.Ospeed) } func Tiocinq(fd uintptr) (int, error) { return 0, nil } + +// Tiocoutq return the number of bytes in the output buffer. +func Tiocoutq(fd uintptr) (int, error) { + return unix.IoctlGetInt(int(fd), unix.TIOCOUTQ) +} diff --git a/vendor/github.com/pkg/term/termios/termios_linux.go b/vendor/github.com/pkg/term/termios/termios_linux.go index 131a64b7..9315fe4c 100644 --- a/vendor/github.com/pkg/term/termios/termios_linux.go +++ b/vendor/github.com/pkg/term/termios/termios_linux.go @@ -5,6 +5,13 @@ import ( ) const ( + TCSETS = 0x5402 + TCSETSW = 0x5403 + TCSETSF = 0x5404 + TCFLSH = 0x540B + TCSBRK = 0x5409 + TCSBRKP = 0x5425 + IXON = 0x00000400 IXANY = 0x00000800 IXOFF = 0x00001000 @@ -12,8 +19,8 @@ const ( ) // Tcgetattr gets the current serial port settings. -func Tcgetattr(fd uintptr) (*unix.Termios, error) { - return unix.IoctlGetTermios(int(fd), unix.TCGETS) +func Tcgetattr(fd uintptr, argp *unix.Termios) error { + return unix.IoctlSetTermios(int(fd), unix.TCGETS, argp) } // Tcsetattr sets the current serial port settings. @@ -21,11 +28,11 @@ func Tcsetattr(fd, action uintptr, argp *unix.Termios) error { var request uintptr switch action { case TCSANOW: - request = unix.TCSETS + request = TCSETS case TCSADRAIN: - request = unix.TCSETSW + request = TCSETSW case TCSAFLUSH: - request = unix.TCSETSF + request = TCSETSF default: return unix.EINVAL } @@ -37,23 +44,23 @@ func Tcsetattr(fd, action uintptr, argp *unix.Termios) error { // duration is zero, it transmits zero-valued bits for at least 0.25 seconds, and not more that 0.5 seconds. // If duration is not zero, it sends zero-valued bits for some // implementation-defined length of time. -func Tcsendbreak(fd uintptr, duration int) error { - return unix.IoctlSetInt(int(fd), unix.TCSBRKP, duration) +func Tcsendbreak(fd, duration uintptr) error { + return ioctl(fd, TCSBRKP, duration) } // Tcdrain waits until all output written to the object referred to by fd has been transmitted. func Tcdrain(fd uintptr) error { // simulate drain with TCSADRAIN - attr, err := Tcgetattr(fd) - if err != nil { + var attr unix.Termios + if err := Tcgetattr(fd, &attr); err != nil { return err } - return Tcsetattr(fd, TCSADRAIN, attr) + return Tcsetattr(fd, TCSADRAIN, &attr) } // Tcflush discards data written to the object referred to by fd but not transmitted, or data received but not read, depending on the value of selector. func Tcflush(fd, selector uintptr) error { - return unix.IoctlSetInt(int(fd), unix.TCFLSH, int(selector)) + return ioctl(fd, TCFLSH, selector) } // Tiocinq returns the number of bytes in the input buffer. @@ -61,6 +68,11 @@ func Tiocinq(fd uintptr) (int, error) { return unix.IoctlGetInt(int(fd), unix.TIOCINQ) } +// Tiocoutq return the number of bytes in the output buffer. +func Tiocoutq(fd uintptr) (int, error) { + return unix.IoctlGetInt(int(fd), unix.TIOCOUTQ) +} + // Cfgetispeed returns the input baud rate stored in the termios structure. func Cfgetispeed(attr *unix.Termios) uint32 { return attr.Ispeed } diff --git a/vendor/github.com/pkg/term/termios/termios_solaris.go b/vendor/github.com/pkg/term/termios/termios_solaris.go index 959ceb38..cea79f18 100644 --- a/vendor/github.com/pkg/term/termios/termios_solaris.go +++ b/vendor/github.com/pkg/term/termios/termios_solaris.go @@ -13,6 +13,7 @@ const ( TCSETS = 0x5402 TCSETSW = 0x5403 TCSETSF = 0x5404 + TCFLSH = 0x540B TCSBRK = 0x5409 TCSBRKP = 0x5425 @@ -22,9 +23,14 @@ const ( CRTSCTS = 0x80000000 ) +// See /usr/include/sys/termios.h +const FIORDCHK = C.FIORDCHK + // Tcgetattr gets the current serial port settings. -func Tcgetattr(fd uintptr) (*unix.Termios, error) { - return unix.IoctlGetTermios(int(fd), unix.TCGETS) +func Tcgetattr(fd uintptr, argp *unix.Termios) error { + termios, err := unix.IoctlGetTermios(int(fd), unix.TCGETS) + *argp = *(tiosTounix(termios)) + return err } // Tcsetattr sets the current serial port settings. @@ -37,8 +43,8 @@ func Tcsetattr(fd, action uintptr, argp *unix.Termios) error { // duration is zero, it transmits zero-valued bits for at least 0.25 seconds, and not more that 0.5 seconds. // If duration is not zero, it sends zero-valued bits for some // implementation-defined length of time. -func Tcsendbreak(fd uintptr, duration int) error { - return ioctl(fd, TCSBRKP, uintptr(duration)) +func Tcsendbreak(fd, duration uintptr) error { + return ioctl(fd, TCSBRKP, duration) } // Tcdrain waits until all output written to the object referred to by fd has been transmitted. @@ -53,12 +59,18 @@ func Tcdrain(fd uintptr) error { // Tcflush discards data written to the object referred to by fd but not transmitted, or data received but not read, depending on the value of selector. func Tcflush(fd, selector uintptr) error { - return ioctl(fd, unix.TCFLSH, selector) + return ioctl(fd, TCFLSH, selector) } // Tiocinq returns the number of bytes in the input buffer. -func Tiocinq(fd uintptr) (int, error) { - return unix.IoctlGetInt(int(fd), unix.FIORDCHK) +func Tiocinq(fd uintptr, argp *int) (err error) { + *argp, err = unix.IoctlGetInt(int(fd), FIORDCHK) + return err +} + +// Tiocoutq return the number of bytes in the output buffer. +func Tiocoutq(fd uintptr, argp *int) error { + return ioctl(fd, unix.TIOCOUTQ, uintptr(unsafe.Pointer(argp))) } // Cfgetispeed returns the input baud rate stored in the termios structure. diff --git a/vendor/github.com/pkg/term/termios/termios_windows.go b/vendor/github.com/pkg/term/termios/termios_windows.go new file mode 100644 index 00000000..884378cb --- /dev/null +++ b/vendor/github.com/pkg/term/termios/termios_windows.go @@ -0,0 +1 @@ +package termios diff --git a/vendor/modules.txt b/vendor/modules.txt index 158fda26..3aeaa3e0 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -22,7 +22,7 @@ github.com/blacknon/go-sshlib # github.com/blacknon/textcol v0.0.1 ## explicit github.com/blacknon/textcol -# github.com/c-bata/go-prompt v0.2.6 +# github.com/c-bata/go-prompt v0.2.5 ## explicit; go 1.14 github.com/c-bata/go-prompt github.com/c-bata/go-prompt/completer @@ -78,7 +78,7 @@ github.com/pkg/errors # github.com/pkg/sftp v1.10.1 ## explicit; go 1.12 github.com/pkg/sftp -# github.com/pkg/term v1.2.0-beta.2 +# github.com/pkg/term v1.1.0 ## explicit; go 1.14 github.com/pkg/term/termios # github.com/pmezard/go-difflib v1.0.0