From 61bfb3cfa8857a144460d05330c1d1fccded960b Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Sun, 9 Dec 2018 17:44:33 -0800 Subject: Make password prompt compatible with Windows --- cli/ask_credentials.go | 14 ++++++++++++-- go.mod | 2 +- go.sum | 2 ++ locale/locale.go | 0 locale/translations.go | 0 locale/translations/pl_PL.json | 0 reader/parser/debug.test | Bin 9543972 -> 0 bytes 7 files changed, 15 insertions(+), 3 deletions(-) mode change 100755 => 100644 locale/locale.go mode change 100755 => 100644 locale/translations.go mode change 100755 => 100644 locale/translations/pl_PL.json delete mode 100755 reader/parser/debug.test diff --git a/cli/ask_credentials.go b/cli/ask_credentials.go index bd4bf5f..9021d9b 100644 --- a/cli/ask_credentials.go +++ b/cli/ask_credentials.go @@ -14,13 +14,23 @@ import ( ) func askCredentials() (string, string) { - reader := bufio.NewReader(os.Stdin) + fd := int(os.Stdin.Fd()) + + if !terminal.IsTerminal(fd) { + fmt.Fprintf(os.Stderr, "This is not a terminal, exiting.") + os.Exit(1) + } fmt.Print("Enter Username: ") + + reader := bufio.NewReader(os.Stdin) username, _ := reader.ReadString('\n') fmt.Print("Enter Password: ") - bytePassword, _ := terminal.ReadPassword(0) + + state, _ := terminal.GetState(fd) + defer terminal.Restore(fd, state) + bytePassword, _ := terminal.ReadPassword(fd) fmt.Printf("\n") return strings.TrimSpace(username), strings.TrimSpace(string(bytePassword)) diff --git a/go.mod b/go.mod index 577e270..789f294 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( github.com/lib/pq v1.0.0 github.com/tdewolff/minify v2.3.5+incompatible // indirect github.com/tdewolff/parse v2.3.3+incompatible // indirect - golang.org/x/crypto v0.0.0-20180820150726-614d502a4dac + golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9 golang.org/x/net v0.0.0-20180826012351-8a410e7b638d golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f // indirect diff --git a/go.sum b/go.sum index 213c0f3..e5ef72a 100644 --- a/go.sum +++ b/go.sum @@ -20,6 +20,8 @@ golang.org/x/crypto v0.0.0-20180621125126-a49355c7e3f8 h1:h7zdf0RiEvWbYBKIx4b+q4 golang.org/x/crypto v0.0.0-20180621125126-a49355c7e3f8/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20180820150726-614d502a4dac h1:7d7lG9fHOLdL6jZPtnV4LpI41SbohIJ1Atq7U991dMg= golang.org/x/crypto v0.0.0-20180820150726-614d502a4dac/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9 h1:mKdxBk7AujPs8kU4m80U72y/zjbZ3UcXC7dClwKbUI0= +golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/net v0.0.0-20180218175443-cbe0f9307d01/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180706051357-32a936f46389 h1:U+zCn5sqaq+q4hrnMrz9sgrW1yatwEOUgYkGt3u9ZOU= golang.org/x/net v0.0.0-20180706051357-32a936f46389/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= diff --git a/locale/locale.go b/locale/locale.go old mode 100755 new mode 100644 diff --git a/locale/translations.go b/locale/translations.go old mode 100755 new mode 100644 diff --git a/locale/translations/pl_PL.json b/locale/translations/pl_PL.json old mode 100755 new mode 100644 diff --git a/reader/parser/debug.test b/reader/parser/debug.test deleted file mode 100755 index f97b9b3..0000000 Binary files a/reader/parser/debug.test and /dev/null differ -- cgit v1.2.3