]> git.lizzy.rs Git - micro.git/blobdiff - src/messenger.go
Add flags and yes no prompt
[micro.git] / src / messenger.go
index ca80b1b4278e8fde3c5b31324fc3a4becfe3f634..e7984bf30bc99c3909b15251b4b4d21690ca82f1 100644 (file)
@@ -71,6 +71,29 @@ func (m *Messenger) Error(msg string) {
        m.hasMessage = true
 }
 
+// YesNoPrompt asks the user a yes or no question (waits for y or n) and returns the result
+func (m *Messenger) YesNoPrompt(prompt string) bool {
+       m.Message(prompt)
+
+       for {
+               m.Clear()
+               m.Display()
+               screen.Show()
+               event := screen.PollEvent()
+
+               switch e := event.(type) {
+               case *tcell.EventKey:
+                       if e.Key() == tcell.KeyRune {
+                               if e.Rune() == 'y' {
+                                       return true
+                               } else if e.Rune() == 'n' {
+                                       return false
+                               }
+                       }
+               }
+       }
+}
+
 // Prompt sends the user a message and waits for a response to be typed in
 // This function blocks the main loop while waiting for input
 func (m *Messenger) Prompt(prompt string) (string, bool) {