Skip to content

Commit

Permalink
Merge pull request #192 from dmitryk-dk/v3-pooling
Browse files Browse the repository at this point in the history
Update dependencies, use Syscall instead of Syscall6
  • Loading branch information
cheggaaa committed May 9, 2022
2 parents 90c02fa + 8830ba5 commit 56b7944
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 21 deletions.
2 changes: 1 addition & 1 deletion v3/go.mod
Expand Up @@ -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
4 changes: 2 additions & 2 deletions v3/go.sum
Expand Up @@ -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=
1 change: 1 addition & 0 deletions v3/termutil/term_appengine.go
@@ -1,3 +1,4 @@
//go:build appengine
// +build appengine

package termutil
Expand Down
1 change: 1 addition & 0 deletions 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

Expand Down
4 changes: 2 additions & 2 deletions v3/termutil/term_linux.go
@@ -1,5 +1,5 @@
// +build linux
// +build !appengine
//go:build linux && !appengine
// +build linux,!appengine

package termutil

Expand Down
1 change: 1 addition & 0 deletions 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

Expand Down
4 changes: 2 additions & 2 deletions v3/termutil/term_solaris.go
@@ -1,5 +1,5 @@
// +build solaris
// +build !appengine
//go:build solaris && !appengine
// +build solaris,!appengine

package termutil

Expand Down
1 change: 1 addition & 0 deletions v3/termutil/term_win.go
@@ -1,3 +1,4 @@
//go:build windows
// +build windows

package termutil
Expand Down
27 changes: 13 additions & 14 deletions 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

Expand All @@ -16,6 +17,7 @@ var (
unlockSignals = []os.Signal{
os.Interrupt, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGKILL,
}
oldState syscall.Termios
)

type window struct {
Expand Down Expand Up @@ -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
}

0 comments on commit 56b7944

Please sign in to comment.