summaryrefslogtreecommitdiff
path: root/menu/confirm.go
diff options
context:
space:
mode:
authorewy <ewy0@protonmail.com>2026-04-14 16:37:17 +0200
committerewy <ewy0@protonmail.com>2026-04-14 16:37:17 +0200
commit45a297a8e526094e8fce6e2c5c0fd89b381d1765 (patch)
tree852ebc3a0112c94dc9726d0b27ab057bf6383660 /menu/confirm.go
i have to commit at some point!
Diffstat (limited to 'menu/confirm.go')
-rw-r--r--menu/confirm.go43
1 files changed, 43 insertions, 0 deletions
diff --git a/menu/confirm.go b/menu/confirm.go
new file mode 100644
index 0000000..b9063c9
--- /dev/null
+++ b/menu/confirm.go
@@ -0,0 +1,43 @@
+package menu
+
+import (
+ "bufio"
+ "fmt"
+ "github.com/charmbracelet/lipgloss"
+ "io"
+ "os"
+ "pik/menu/style"
+ "pik/model"
+ "slices"
+)
+
+var confirmations = []rune{
+ 'y',
+ 'Y',
+ ' ',
+ '\n',
+}
+
+var (
+ PromptColor = lipgloss.Color("1")
+ PromptStyle = style.New(func() lipgloss.Style {
+ return lipgloss.NewStyle().Foreground(PromptColor)
+ })
+ ConfirmStyle = style.New(func() lipgloss.Style {
+ return lipgloss.NewStyle()
+ })
+)
+
+func Confirm(r io.Reader, source *model.Source, target model.Target, args ...string) bool {
+ banner := ConfirmStyle.Render(PromptStyle.Render("[Y/n]"), Banner(source, target, args...), "? ")
+ fmt.Print(banner)
+ scanner := bufio.NewScanner(r)
+ scanner.Split(bufio.ScanRunes)
+ scanner.Scan()
+ if slices.Contains(confirmations, []rune(scanner.Text())[0]) {
+ return true
+ } else {
+ _, _ = fmt.Fprint(os.Stderr, "confirmation was not given.")
+ }
+ return false
+}