Skip to content

Commit 8bf5c86

Browse files
committed
feat(less frustrating confirmation modals)
1 parent cc721cb commit 8bf5c86

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

internal/ui/dialogs/confirm.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@ package dialogs
22

33
import (
44
"fmt"
5+
"strings"
56

67
"github.com/gdamore/tcell/v2"
78
"github.com/jr-k/d4s/internal/ui/common"
89
"github.com/jr-k/d4s/internal/ui/styles"
910
"github.com/rivo/tview"
1011
)
1112

12-
// ShowConfirmation shows a modal asking to type "Yes Please!" and allows forcing
13+
// ShowConfirmation shows a modal asking to type "y" or "yes" and allows forcing
1314
func ShowConfirmation(app common.AppController, actionName, item string, onConfirm func(force bool)) {
1415
// Center the dialog
1516
dialogWidth := 60
@@ -21,7 +22,7 @@ func ShowConfirmation(app common.AppController, actionName, item string, onConfi
2122
text := tview.NewTextView().
2223
SetDynamicColors(true).
2324
SetTextAlign(tview.AlignCenter).
24-
SetText(fmt.Sprintf("\n[red::b] DANGER ZONE \n\n[white::-]You are about to %s:\n[yellow] %s [white]\n\nType exactly: [red::b]Yes Please![white::-]", actionName, item))
25+
SetText(fmt.Sprintf("\n[red::b] DANGER ZONE \n\n[white::-]You are about to %s:\n[yellow] %s [white]\n\nType [red::b]y[white::-] or [red::b]yes[white::-] to confirm", actionName, item))
2526
text.SetBackgroundColor(styles.ColorBlack)
2627

2728
// Force Checkbox
@@ -165,7 +166,8 @@ func ShowConfirmation(app common.AppController, actionName, item string, onConfi
165166
return nil
166167
}
167168
if event.Key() == tcell.KeyEnter {
168-
if input.GetText() == "Yes Please!" {
169+
val := strings.ToLower(strings.TrimSpace(input.GetText()))
170+
if val == "y" || val == "yes" {
169171
closeModal()
170172
onConfirm(force)
171173
}
@@ -176,7 +178,8 @@ func ShowConfirmation(app common.AppController, actionName, item string, onConfi
176178

177179
input.SetDoneFunc(func(key tcell.Key) {
178180
if key == tcell.KeyEnter {
179-
if input.GetText() == "Yes Please!" {
181+
val := strings.ToLower(strings.TrimSpace(input.GetText()))
182+
if val == "y" || val == "yes" {
180183
closeModal()
181184
onConfirm(force)
182185
} else {

0 commit comments

Comments
 (0)