-
Notifications
You must be signed in to change notification settings - Fork 11
/
model.go
40 lines (33 loc) · 830 Bytes
/
model.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
package main
import (
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
)
type model struct {
flipper tea.Model
width, height int
}
// Init is the bubbletea init function.
func (m model) Init() tea.Cmd {
return m.flipper.Init()
}
// Update is the bubbletea update function and handles all tea.Msgs.
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg := msg.(type) {
case tea.KeyMsg:
switch msg.String() {
case "ctrl+c":
return m, tea.Quit
}
case tea.WindowSizeMsg:
m.width = msg.Width
m.height = msg.Height
}
var cmd tea.Cmd
m.flipper, cmd = m.flipper.Update(msg)
return m, cmd
}
// View is the bubbletea view function.
func (m model) View() string {
return lipgloss.Place(m.width, m.height, lipgloss.Center, lipgloss.Center, m.flipper.View())
}