diff options
author | Santo Cariotti <santo@dcariotti.me> | 2025-04-17 10:52:47 +0200 |
---|---|---|
committer | Santo Cariotti <santo@dcariotti.me> | 2025-04-17 10:52:47 +0200 |
commit | 313c96613153d92e4964bef4d2469b09a9505597 (patch) | |
tree | 0b7e8e58f826a2ef4821145eb27b045cf760849c /pkg/ui/views/game_keymap.go | |
parent | 39a594829ebddc0bc06b92465241439f81fca205 (diff) |
Split views on subfiles
Diffstat (limited to 'pkg/ui/views/game_keymap.go')
-rw-r--r-- | pkg/ui/views/game_keymap.go | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/pkg/ui/views/game_keymap.go b/pkg/ui/views/game_keymap.go new file mode 100644 index 0000000..dff75a9 --- /dev/null +++ b/pkg/ui/views/game_keymap.go @@ -0,0 +1,54 @@ +package views + +import ( + "fmt" + + "github.com/charmbracelet/bubbles/key" + tea "github.com/charmbracelet/bubbletea" + "github.com/charmbracelet/lipgloss" +) + +// gameKeyMap defines the key bindings for the game view. +type gameKeyMap struct { + GoLogout key.Binding + Quit key.Binding +} + +// defaultGameKeyMap provides the default key bindings for the game view. +var defaultGameKeyMap = gameKeyMap{ + GoLogout: key.NewBinding( + key.WithKeys("alt+Q", "alt+q"), + key.WithHelp("Alt+Q", "Logout"), + ), + Quit: key.NewBinding( + key.WithKeys("Q", "q"), + key.WithHelp(" Q", "Quit"), + ), +} + +func (m GameModel) handleKeyMsg(msg tea.KeyMsg) (GameModel, tea.Cmd) { + switch { + case key.Matches(msg, m.keys.GoLogout): + return m, logout(m.width, m.height+1) + case key.Matches(msg, m.keys.Quit): + return m, tea.Quit + } + + return m, nil +} + +func (m GameModel) renderNavigationButtons() string { + logoutKey := fmt.Sprintf("%s %s", + altCodeStyle.Render(m.keys.GoLogout.Help().Key), + m.keys.GoLogout.Help().Desc) + + quitKey := fmt.Sprintf("%s %s", + altCodeStyle.Render(m.keys.Quit.Help().Key), + m.keys.Quit.Help().Desc) + + return lipgloss.JoinVertical( + lipgloss.Left, + logoutKey, + quitKey, + ) +} |