mirror of
https://github.com/crunchy-labs/crunchy-cli.git
synced 2026-01-21 12:12:00 -06:00
Remove library & refactor cli
This commit is contained in:
parent
0fed0f8d3b
commit
8a3e42e4d1
45 changed files with 117 additions and 3687 deletions
41
commands/windows.go
Normal file
41
commands/windows.go
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
//go:build windows
|
||||
|
||||
package commands
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"os"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
// https://github.com/bgentry/speakeasy/blob/master/speakeasy_windows.go
|
||||
func readLineSilent() ([]byte, error) {
|
||||
var oldMode uint32
|
||||
|
||||
if err := syscall.GetConsoleMode(syscall.Stdin, &oldMode); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
newMode := oldMode &^ 0x0004
|
||||
|
||||
err := setConsoleMode(syscall.Stdin, newMode)
|
||||
defer setConsoleMode(syscall.Stdin, oldMode)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
l, _, err := bufio.NewReader(os.Stdin).ReadLine()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return l, err
|
||||
}
|
||||
|
||||
func setConsoleMode(console syscall.Handle, mode uint32) error {
|
||||
dll := syscall.MustLoadDLL("kernel32")
|
||||
proc := dll.MustFindProc("SetConsoleMode")
|
||||
_, _, err := proc.Call(uintptr(console), uintptr(mode))
|
||||
|
||||
return err
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue