summaryrefslogtreecommitdiff
path: root/internal/prompt
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2024-10-09 23:44:09 +0300
committerPaul Buetow <paul@buetow.org>2024-10-09 23:44:09 +0300
commitaf7c12e5d42b6a19fd657138862ca6db6942d402 (patch)
tree7a7914fa145e7affafc1bb8e4abadcebef12dacb /internal/prompt
parent8e23c12025fac69c6c08aa37e690ee24978c6eed (diff)
refactor
Diffstat (limited to 'internal/prompt')
-rw-r--r--internal/prompt/prompt.go34
1 files changed, 34 insertions, 0 deletions
diff --git a/internal/prompt/prompt.go b/internal/prompt/prompt.go
new file mode 100644
index 0000000..0afe98e
--- /dev/null
+++ b/internal/prompt/prompt.go
@@ -0,0 +1,34 @@
+package prompt
+
+import (
+ "bufio"
+ "errors"
+ "fmt"
+ "os"
+ "strings"
+)
+
+var ErrAborted = errors.New("aborted")
+
+func Yes(question string) bool {
+ reader := bufio.NewReader(os.Stdin)
+
+ for {
+ fmt.Print(question, " (y/n): ")
+ input, err := reader.ReadString('\n')
+ if err != nil {
+ fmt.Println("Error reading input:", err)
+ continue
+ }
+
+ input = strings.TrimSpace(input)
+ switch strings.ToLower(input) {
+ case "y", "yes":
+ return true
+ case "n", "no":
+ return false
+ default:
+ fmt.Println("Please enter 'y' or 'n'.")
+ }
+ }
+}