Skip to content

Commit 779960b

Browse files
committed
feat: place flipper in the center of the screen
1 parent 77ee0fc commit 779960b

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

model.go

+9-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ package main
22

33
import (
44
tea "github.com/charmbracelet/bubbletea"
5+
"github.com/charmbracelet/lipgloss"
56
)
67

78
type model struct {
8-
flipper tea.Model
9+
flipper tea.Model
10+
width, height int
911
}
1012

1113
func (m model) Init() tea.Cmd {
@@ -19,12 +21,17 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
1921
case "ctrl+c":
2022
return m, tea.Quit
2123
}
24+
25+
case tea.WindowSizeMsg:
26+
m.width = msg.Width
27+
m.height = msg.Height
2228
}
29+
2330
var cmd tea.Cmd
2431
m.flipper, cmd = m.flipper.Update(msg)
2532
return m, cmd
2633
}
2734

2835
func (m model) View() string {
29-
return m.flipper.View()
36+
return lipgloss.Place(m.width, m.height, lipgloss.Center, lipgloss.Center, m.flipper.View())
3037
}

0 commit comments

Comments
 (0)