CreateConfirmDialog creates a confirmation dialog.
(title, message string, onConfirm, onCancel func())
| 34 | |
| 35 | // CreateConfirmDialog creates a confirmation dialog. |
| 36 | func CreateConfirmDialog(title, message string, onConfirm, onCancel func()) *tview.Modal { |
| 37 | modal := tview.NewModal() |
| 38 | modal.SetText(message) |
| 39 | // modal.SetBackgroundColor(theme.Colors.Background) |
| 40 | modal.SetTextColor(theme.Colors.Primary) |
| 41 | modal.SetBorderColor(theme.Colors.Border) |
| 42 | modal.SetTitle(title) |
| 43 | modal.SetTitleColor(theme.Colors.Title) |
| 44 | |
| 45 | // Add buttons |
| 46 | modal.AddButtons([]string{"Yes", "No"}) |
| 47 | modal.SetDoneFunc(func(buttonIndex int, buttonLabel string) { |
| 48 | if buttonIndex == 0 && onConfirm != nil { |
| 49 | onConfirm() |
| 50 | } else if onCancel != nil { |
| 51 | onCancel() |
| 52 | } |
| 53 | }) |
| 54 | |
| 55 | // Add keyboard shortcuts for Y/N keys |
| 56 | modal.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey { |
| 57 | switch event.Rune() { |
| 58 | case 'y', 'Y': |
| 59 | if onConfirm != nil { |
| 60 | onConfirm() |
| 61 | } |
| 62 | return nil |
| 63 | case 'n', 'N': |
| 64 | if onCancel != nil { |
| 65 | onCancel() |
| 66 | } |
| 67 | return nil |
| 68 | } |
| 69 | return event |
| 70 | }) |
| 71 | |
| 72 | return modal |
| 73 | } |
| 74 | |
| 75 | // createBaseModal creates a base modal with common configuration. |
| 76 | func createBaseModal(title, message string, textColor tcell.Color, onClose func()) *tview.Modal { |
no test coverage detected