forked from DerTimonius/twkb
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfirmation.go
More file actions
48 lines (41 loc) · 961 Bytes
/
confirmation.go
File metadata and controls
48 lines (41 loc) · 961 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package main
import (
"fmt"
"github.com/DerTimonius/twkb/styles"
"github.com/charmbracelet/bubbles/key"
tea "github.com/charmbracelet/bubbletea"
)
type Confirmation struct {
confirm func() tea.Cmd
message string
column column
index int
}
func (c Confirmation) Init() tea.Cmd {
return nil
}
func NewConfirmation(message string, confirm func() tea.Cmd) *Confirmation {
return &Confirmation{
confirm: confirm,
message: message,
column: column{},
index: 0,
}
}
func (c Confirmation) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg := msg.(type) {
case tea.KeyMsg:
switch {
case key.Matches(msg, keys.Yes):
return board.Update(c)
case key.Matches(msg, keys.No), key.Matches(msg, keys.Back):
return board.Update(nil)
case key.Matches(msg, keys.Quit):
return c, tea.Quit
}
}
return c, nil
}
func (c Confirmation) View() string {
return styles.ConfirmationStyle.Render(fmt.Sprintf("%s (y/n)", c.message))
}