diff options
| author | Stefan Majewsky <majewsky@gmx.net> | 2017-05-05 20:32:19 +0200 |
|---|---|---|
| committer | Stefan Majewsky <majewsky@gmx.net> | 2017-05-05 20:32:19 +0200 |
| commit | 22d80eda906d1958dfde5072717a12995ee6df2d (patch) | |
| tree | 2a27f0f621404fce50594a4c5c6ad547cf51e9ab /pkg/cli | |
| parent | e1022c29c33363bd3c2471b7cef2d37dbd704dca (diff) | |
| download | gofu-22d80eda906d1958dfde5072717a12995ee6df2d.tar.gz | |
implement rtree drop
rtree is functionally complete, but the implementation is very messy
now. :(
Diffstat (limited to 'pkg/cli')
| -rw-r--r-- | pkg/cli/query.go | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/pkg/cli/query.go b/pkg/cli/query.go index 0d367be..40baaec 100644 --- a/pkg/cli/query.go +++ b/pkg/cli/query.go @@ -28,6 +28,26 @@ import ( terminal "golang.org/x/crypto/ssh/terminal" ) +//Confirm displays a yes/no question and returns whether the user answered "yes". +func Confirm(question string) bool { + os.Stdout.Write([]byte(strings.TrimSpace(question) + " [y/n] ")) + + buf := buffer{Input: os.Stdin} + for { + switch string(buf.getNextInput()) { + case "y", "Y": + os.Stdout.Write([]byte("-> yes\n")) + return true + case "n", "N": + os.Stdout.Write([]byte("-> no\n")) + return false + case "\x03": // Ctrl-C + fmt.Fprintln(os.Stderr, "\nInterrupted!") + os.Exit(255) + } + } +} + //Choice is a thing that the user can choose during Query(). type Choice struct { //If given, the choice can be selected by pressing the key that @@ -89,8 +109,6 @@ OUTER: case "\x03": // Ctrl-C fmt.Fprintln(os.Stderr, "Interrupted!") os.Exit(255) - default: - fmt.Printf("%#v\n", string(input)) } //prepare to re-render choices |
