mirror of
https://github.com/crunchy-labs/crunchy-cli.git
synced 2026-01-21 12:12:00 -06:00
Move and refactor files and some more changes :3
This commit is contained in:
parent
781e520591
commit
303689ecbb
29 changed files with 1305 additions and 1160 deletions
48
cli/commands/unix.go
Normal file
48
cli/commands/unix.go
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
//go:build aix || darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris || zos
|
||||
|
||||
package commands
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"os"
|
||||
"os/exec"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
// https://github.com/bgentry/speakeasy/blob/master/speakeasy_unix.go
|
||||
var stty string
|
||||
|
||||
func init() {
|
||||
var err error
|
||||
if stty, err = exec.LookPath("stty"); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func ReadLineSilent() ([]byte, error) {
|
||||
pid, err := setEcho(false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer setEcho(true)
|
||||
|
||||
syscall.Wait4(pid, nil, 0, nil)
|
||||
|
||||
l, _, err := bufio.NewReader(os.Stdin).ReadLine()
|
||||
return l, err
|
||||
}
|
||||
|
||||
func setEcho(on bool) (pid int, err error) {
|
||||
fds := []uintptr{os.Stdin.Fd(), os.Stdout.Fd(), os.Stderr.Fd()}
|
||||
|
||||
if on {
|
||||
pid, err = syscall.ForkExec(stty, []string{"stty", "echo"}, &syscall.ProcAttr{Files: fds})
|
||||
} else {
|
||||
pid, err = syscall.ForkExec(stty, []string{"stty", "-echo"}, &syscall.ProcAttr{Files: fds})
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue