-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
71 lines (58 loc) · 1.35 KB
/
main.go
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package main
import (
"fmt"
"os"
tea "github.com/charmbracelet/bubbletea"
gloss "github.com/charmbracelet/lipgloss"
"github.com/shawalli/bubbles/radio"
)
type Model struct {
vRadio radio.Model
hRadio radio.Model
}
func (m Model) Init() tea.Cmd { return nil }
func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg := msg.(type) {
case tea.KeyMsg:
switch msg.String() {
case "esc", "q", "ctrl+c":
return m, tea.Quit
}
}
t, _ := m.hRadio.Update(msg)
m.hRadio = t.(radio.Model)
t, _ = m.vRadio.Update(msg)
m.vRadio = t.(radio.Model)
return m, nil
}
func (m Model) View() string {
return gloss.JoinVertical(
gloss.Top,
m.vRadio.View(),
m.hRadio.View(),
)
}
func main() {
vButtons := []tea.Model{
radio.NewButton(" 10% "),
radio.NewButton(" 15% "),
radio.NewButton(" 20% "),
radio.NewButton(" 22% "),
radio.NewButton(" 25% "),
radio.NewButton("None "),
}
hButtons := []tea.Model{
radio.NewButton(" Pay Cash "),
radio.NewButton("Pay Credit "),
radio.NewButton(" PayBuddy "),
radio.NewButton(" BNPL "),
}
m := Model{
vRadio: radio.New(true, vButtons...).Styles(radio.DefaultPillStyles(true)),
hRadio: radio.New(false, hButtons...).Styles(radio.DefaultPillStyles(false)),
}
if _, err := tea.NewProgram(m).Run(); err != nil {
fmt.Printf("could not run program: %v", err)
os.Exit(1)
}
}