aboutsummaryrefslogtreecommitdiff
path: root/pkg/client/input.go
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/client/input.go')
-rw-r--r--pkg/client/input.go26
1 files changed, 26 insertions, 0 deletions
diff --git a/pkg/client/input.go b/pkg/client/input.go
new file mode 100644
index 0000000..8c814a6
--- /dev/null
+++ b/pkg/client/input.go
@@ -0,0 +1,26 @@
+package client
+
+import (
+ "bufio"
+ "os"
+
+ "github.com/pkg/errors"
+)
+
+// getValidInput returns the selected menu command as a string or an error
+func (s *State) getValidInput() (string, error) {
+ menu := s.config.Menus[s.currentMenu]
+
+ reader := bufio.NewReader(os.Stdin)
+ for {
+ input, err := reader.ReadByte()
+ if err != nil {
+ return "", errors.Wrapf(err, "Could not read byte from stdin")
+ }
+ for _, menuEntry := range menu.MenuEntries {
+ if []byte(menuEntry.Key)[0] == input {
+ return menuEntry.Action, nil
+ }
+ }
+ }
+}