mirror of https://github.com/hashicorp/consul
Updates bgentry/speakeasy.
parent
287a5ef75e
commit
12da41e873
|
@ -1,2 +0,0 @@
|
|||
example/example
|
||||
example/example.exe
|
|
@ -16,14 +16,14 @@ func Ask(prompt string) (password string, err error) {
|
|||
|
||||
// Same as the Ask function, except it is possible to specify the file to write
|
||||
// the prompt to.
|
||||
func FAsk(file *os.File, prompt string) (password string, err error) {
|
||||
func FAsk(wr io.Writer, prompt string) (password string, err error) {
|
||||
if prompt != "" {
|
||||
fmt.Fprint(file, prompt) // Display the prompt.
|
||||
fmt.Fprint(wr, prompt) // Display the prompt.
|
||||
}
|
||||
password, err = getPassword()
|
||||
|
||||
// Carriage return after the user input.
|
||||
fmt.Fprintln(file, "")
|
||||
fmt.Fprintln(wr, "")
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
package speakeasy
|
||||
|
||||
import (
|
||||
"os"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
|
@ -12,18 +11,17 @@ import (
|
|||
const ENABLE_ECHO_INPUT = 0x0004
|
||||
|
||||
func getPassword() (password string, err error) {
|
||||
hStdin := syscall.Handle(os.Stdin.Fd())
|
||||
var oldMode uint32
|
||||
|
||||
err = syscall.GetConsoleMode(hStdin, &oldMode)
|
||||
err = syscall.GetConsoleMode(syscall.Stdin, &oldMode)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
var newMode uint32 = (oldMode &^ ENABLE_ECHO_INPUT)
|
||||
|
||||
err = setConsoleMode(hStdin, newMode)
|
||||
defer setConsoleMode(hStdin, oldMode)
|
||||
err = setConsoleMode(syscall.Stdin, newMode)
|
||||
defer setConsoleMode(syscall.Stdin, oldMode)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
|
|
@ -39,12 +39,16 @@
|
|||
"revisionTime": "2016-01-15T23:47:25Z"
|
||||
},
|
||||
{
|
||||
"checksumSHA1": "dvd7Su+WNmHRP1+w1HezrPUCDsc=",
|
||||
"path": "github.com/bgentry/speakeasy",
|
||||
"revision": "36e9cfdd690967f4f690c6edcc9ffacd006014a0"
|
||||
"revision": "e1439544d8ecd0f3e9373a636d447668096a8f81",
|
||||
"revisionTime": "2016-05-20T23:26:10Z"
|
||||
},
|
||||
{
|
||||
"checksumSHA1": "twtRfb6484vfr2qqjiFkLThTjcQ=",
|
||||
"path": "github.com/bgentry/speakeasy/example",
|
||||
"revision": "36e9cfdd690967f4f690c6edcc9ffacd006014a0"
|
||||
"revision": "e1439544d8ecd0f3e9373a636d447668096a8f81",
|
||||
"revisionTime": "2016-05-20T23:26:10Z"
|
||||
},
|
||||
{
|
||||
"comment": "v1.2.1",
|
||||
|
|
Loading…
Reference in New Issue