-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.go
104 lines (87 loc) · 2.1 KB
/
app.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package main
import (
"fmt"
"time"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
// "github.com/fogleman/ease"
"github.com/lazytf/internal/ui"
"github.com/lazytf/models"
)
func main() {
initialModel := Model{0, false, 10, 0, 0, false, false, 0, 0}
p := tea.NewProgram(initialModel, tea.WithAltScreen())
if _, err := p.Run(); err != nil {
fmt.Println("could not start program:", err)
}
}
type (
tickMsg struct{}
frameMsg struct{}
)
func tick() tea.Cmd {
return tea.Tick(time.Second, func(time.Time) tea.Msg {
return tickMsg{}
})
}
func frame() tea.Cmd {
return tea.Tick(time.Second/60, func(time.Time) tea.Msg {
return frameMsg{}
})
}
type Model models.Model
// type Model struct {
// Choice int
// Chosen bool
// Ticks int
// Frames int
// Progress float64
// Loaded bool
// Quitting bool
// Height, Width int
// }
func (m Model) Init() tea.Cmd {
return tick()
}
// Main update function.
func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
// Make sure these keys always quit
if msg, ok := msg.(tea.KeyMsg); ok {
k := msg.String()
if k == "q" || k == "esc" || k == "ctrl+c" {
m.Quitting = true
return m, tea.Quit
}
}
switch msg := msg.(type) {
case tea.KeyMsg:
switch msg.Type {
case tea.KeyCtrlC:
return m, tea.Quit
}
case tea.WindowSizeMsg:
m.Width = msg.Width
m.Height = msg.Height
}
return m, nil
}
// The main view, which just calls the appropriate sub-view
func (m Model) View() string {
header := lipgloss.NewStyle().
Align(lipgloss.Left).
Width(m.Width).
PaddingLeft(1).
Border(lipgloss.NormalBorder(), false, false).
Render(ui.GetHeader())
footer := lipgloss.NewStyle().
Align(lipgloss.Left).
Width(m.Width).
Render(ui.GetFooter())
contentHeight := (m.Height - lipgloss.Height(header) - lipgloss.Height(footer)) - 2
content := lipgloss.NewStyle().
Width(m.Width).
Height(contentHeight).
Align(lipgloss.Center, lipgloss.Center).
Render(ui.Layout(models.Model(m), contentHeight))
return lipgloss.JoinVertical(lipgloss.Top, header, content, footer)
}