diff options
| author | Stefan Majewsky <majewsky@gmx.net> | 2017-05-02 23:05:09 +0200 |
|---|---|---|
| committer | Stefan Majewsky <majewsky@gmx.net> | 2017-05-02 23:05:09 +0200 |
| commit | c69e9f604c47469429a6a8a27ba7ef873134e0a1 (patch) | |
| tree | 9f1fe244cde4fde4b792b1136770af1e48f6fa6d /pkg/util | |
| parent | 72733e8203654cd26464c8c5a6c955b025102cca (diff) | |
| download | gofu-c69e9f604c47469429a6a8a27ba7ef873134e0a1.tar.gz | |
initial implementation of "rtree get" command
Diffstat (limited to 'pkg/util')
| -rw-r--r-- | pkg/util/util.go | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/pkg/util/util.go b/pkg/util/util.go index 3c5e724..8d2b0bf 100644 --- a/pkg/util/util.go +++ b/pkg/util/util.go @@ -21,6 +21,7 @@ package util import ( "bufio" "fmt" + "io" "os" "sort" "strings" @@ -57,12 +58,12 @@ var stdin = bufio.NewReader(os.Stdin) // // choice := Prompt("(y)es or (n)o", []string{"y","n"}) // //choice is either "y" or "n" -func Prompt(question string, answers []string) string { +func Prompt(out io.Writer, question string, answers []string) string { for idx, answer := range answers { answers[idx] = strings.ToLower(answer) } - os.Stdout.Write([]byte(">> " + strings.TrimSpace(question) + " ")) + out.Write([]byte(">> " + strings.TrimSpace(question) + " ")) for { input, err := stdin.ReadString('\n') FatalIfError(err) @@ -74,17 +75,24 @@ func Prompt(question string, answers []string) string { } //user typed gibberish - ask again - os.Stdout.Write([]byte("Please type ")) + out.Write([]byte("Please type ")) for idx, answer := range answers { if idx > 0 { if idx == len(answers)-1 { - os.Stdout.Write([]byte(" or ")) + out.Write([]byte(" or ")) } else { - os.Stdout.Write([]byte(", ")) + out.Write([]byte(", ")) } } - os.Stdout.Write([]byte("'" + answer + "'")) + out.Write([]byte("'" + answer + "'")) } - os.Stdout.Write([]byte(": ")) + out.Write([]byte(": ")) } } + +//ReadLine reads a line from stdin, with whitespace already trimmed. +func ReadLine() string { + input, err := stdin.ReadString('\n') + FatalIfError(err) + return strings.TrimSpace(input) +} |
