-
Notifications
You must be signed in to change notification settings - Fork 0
/
end-view.go
51 lines (43 loc) · 1.12 KB
/
end-view.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
package main
import (
"fmt"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
"github.com/dziedzicgrzegorz/Tic-Tac-Toe/constants"
)
type EndGameModel struct {
width int
height int
message string
}
func NewEndGameModel(width, height int, endGameMessage string) *EndGameModel {
return &EndGameModel{
width: width,
height: height,
message: endGameMessage,
}
}
func (m *EndGameModel) Init() tea.Cmd {
return nil
}
func (m *EndGameModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg := msg.(type) {
case tea.KeyMsg:
switch msg.String() {
case constants.M:
return initialModel(m.width, m.height), nil
case constants.Quit, constants.CtrlC, constants.Esc:
return m, tea.Quit
}
case tea.WindowSizeMsg:
m.width = msg.Width
m.height = msg.Height
}
return m, nil
}
func (m *EndGameModel) View() string {
message := fmt.Sprintf("%s\n\nPress 'm' to return to menu.", m.message)
styledMessage := constants.HighlightStyle.Render(message)
centeredMessage := lipgloss.Place(m.width, m.height, lipgloss.Center, lipgloss.Center, styledMessage)
return centeredMessage
}