diff --git a/v3/go.mod b/v3/go.mod index ec2b67b..7f0eb4f 100644 --- a/v3/go.mod +++ b/v3/go.mod @@ -7,7 +7,7 @@ require ( github.com/mattn/go-isatty v0.0.12 github.com/mattn/go-runewidth v0.0.12 github.com/rivo/uniseg v0.2.0 // indirect - golang.org/x/sys v0.0.0-20210403161142-5e06dd20ab57 // indirect + golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6 // indirect ) go 1.12 diff --git a/v3/go.sum b/v3/go.sum index 70a1b2b..49d2b3d 100644 --- a/v3/go.sum +++ b/v3/go.sum @@ -13,5 +13,5 @@ github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY= github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210403161142-5e06dd20ab57 h1:F5Gozwx4I1xtr/sr/8CFbb57iKi3297KFs0QDbGN60A= -golang.org/x/sys v0.0.0-20210403161142-5e06dd20ab57/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6 h1:nonptSpoQ4vQjyraW20DXPAglgQfVnM9ZC6MmNLMR60= +golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= diff --git a/v3/termutil/term_appengine.go b/v3/termutil/term_appengine.go index 4b7b20e..6bc5c51 100644 --- a/v3/termutil/term_appengine.go +++ b/v3/termutil/term_appengine.go @@ -1,3 +1,4 @@ +//go:build appengine // +build appengine package termutil diff --git a/v3/termutil/term_bsd.go b/v3/termutil/term_bsd.go index 272659a..e16380f 100644 --- a/v3/termutil/term_bsd.go +++ b/v3/termutil/term_bsd.go @@ -1,3 +1,4 @@ +//go:build (darwin || freebsd || netbsd || openbsd || dragonfly) && !appengine // +build darwin freebsd netbsd openbsd dragonfly // +build !appengine diff --git a/v3/termutil/term_linux.go b/v3/termutil/term_linux.go index 2f59e53..f4c5325 100644 --- a/v3/termutil/term_linux.go +++ b/v3/termutil/term_linux.go @@ -1,5 +1,5 @@ -// +build linux -// +build !appengine +//go:build linux && !appengine +// +build linux,!appengine package termutil diff --git a/v3/termutil/term_nix.go b/v3/termutil/term_nix.go index 14277e7..471d5a9 100644 --- a/v3/termutil/term_nix.go +++ b/v3/termutil/term_nix.go @@ -1,3 +1,4 @@ +//go:build (linux || darwin || freebsd || netbsd || openbsd || dragonfly) && !appengine // +build linux darwin freebsd netbsd openbsd dragonfly // +build !appengine diff --git a/v3/termutil/term_solaris.go b/v3/termutil/term_solaris.go index fc96c2b..45f3055 100644 --- a/v3/termutil/term_solaris.go +++ b/v3/termutil/term_solaris.go @@ -1,5 +1,5 @@ -// +build solaris -// +build !appengine +//go:build solaris && !appengine +// +build solaris,!appengine package termutil diff --git a/v3/termutil/term_win.go b/v3/termutil/term_win.go index 3150dfd..75c7e2c 100644 --- a/v3/termutil/term_win.go +++ b/v3/termutil/term_win.go @@ -1,3 +1,4 @@ +//go:build windows // +build windows package termutil diff --git a/v3/termutil/term_x.go b/v3/termutil/term_x.go index 1674d3e..4746e9b 100644 --- a/v3/termutil/term_x.go +++ b/v3/termutil/term_x.go @@ -1,3 +1,4 @@ +//go:build (linux || darwin || freebsd || netbsd || openbsd || solaris || dragonfly) && !appengine // +build linux darwin freebsd netbsd openbsd solaris dragonfly // +build !appengine @@ -16,6 +17,7 @@ var ( unlockSignals = []os.Signal{ os.Interrupt, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGKILL, } + oldState syscall.Termios ) type window struct { @@ -53,30 +55,27 @@ func TerminalSize() (rows, cols int, err error) { return int(w.Row), int(w.Col), nil } -var oldState syscall.Termios - -func lockEcho() (err error) { +func lockEcho() error { fd := tty.Fd() - if _, _, e := syscall.Syscall6(sysIoctl, fd, ioctlReadTermios, uintptr(unsafe.Pointer(&oldState)), 0, 0, 0); e != 0 { - err = fmt.Errorf("Can't get terminal settings: %v", e) - return + + if _, _, err := syscall.Syscall(sysIoctl, fd, ioctlReadTermios, uintptr(unsafe.Pointer(&oldState))); err != 0 { + return fmt.Errorf("error when puts the terminal connected to the given file descriptor: %w", err) } newState := oldState newState.Lflag &^= syscall.ECHO newState.Lflag |= syscall.ICANON | syscall.ISIG newState.Iflag |= syscall.ICRNL - if _, _, e := syscall.Syscall6(sysIoctl, fd, ioctlWriteTermios, uintptr(unsafe.Pointer(&newState)), 0, 0, 0); e != 0 { - err = fmt.Errorf("Can't set terminal settings: %v", e) - return + if _, _, e := syscall.Syscall(sysIoctl, fd, ioctlWriteTermios, uintptr(unsafe.Pointer(&newState))); e != 0 { + return fmt.Errorf("error update terminal settings: %w", e) } - return + return nil } -func unlockEcho() (err error) { +func unlockEcho() error { fd := tty.Fd() - if _, _, e := syscall.Syscall6(sysIoctl, fd, ioctlWriteTermios, uintptr(unsafe.Pointer(&oldState)), 0, 0, 0); e != 0 { - err = fmt.Errorf("Can't set terminal settings") + if _, _, err := syscall.Syscall(sysIoctl, fd, ioctlWriteTermios, uintptr(unsafe.Pointer(&oldState))); err != 0 { + return fmt.Errorf("error restores the terminal connected to the given file descriptor: %w", err) } - return + return nil }