feat: add navigation and window size handlers with corresponding tests
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"slices"
|
||||
|
||||
"github.com/StevanFreeborn/term-tier/internal/state"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
)
|
||||
|
||||
type helpHandler struct {
|
||||
keys []string
|
||||
description string
|
||||
}
|
||||
|
||||
func NewHelpHandler() KeyMsgHandler {
|
||||
return helpHandler{
|
||||
keys: []string{"?"},
|
||||
description: "Toggle help menu",
|
||||
}
|
||||
}
|
||||
|
||||
func (h helpHandler) KeysHandled() []string {
|
||||
return h.keys
|
||||
}
|
||||
|
||||
func (h helpHandler) Description() string {
|
||||
return h.description
|
||||
}
|
||||
|
||||
func (h helpHandler) Match(s state.State, msg tea.KeyMsg) bool {
|
||||
return s.Mode() == state.NavigationMode && slices.Contains(h.keys, msg.String()) ||
|
||||
s.Mode() == state.HelpMode && slices.Contains(h.keys, msg.String())
|
||||
}
|
||||
|
||||
func (h helpHandler) Handle(s state.State, msg tea.KeyMsg) tea.Cmd {
|
||||
s.ToggleHelp()
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user