feat: add navigation and window size handlers with corresponding tests
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"slices"
|
||||
|
||||
"github.com/StevanFreeborn/term-tier/internal/state"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
)
|
||||
|
||||
type upNavigationHandler struct {
|
||||
keys []string
|
||||
description string
|
||||
}
|
||||
|
||||
func NewUpNavigationHandler() KeyMsgHandler {
|
||||
return upNavigationHandler{
|
||||
keys: []string{"up", "k"},
|
||||
description: "Move up",
|
||||
}
|
||||
}
|
||||
|
||||
func (h upNavigationHandler) KeysHandled() []string {
|
||||
return h.keys
|
||||
}
|
||||
|
||||
func (h upNavigationHandler) Description() string {
|
||||
return h.description
|
||||
}
|
||||
|
||||
func (h upNavigationHandler) Match(s state.State, msg tea.KeyMsg) bool {
|
||||
if s.Mode() != state.NavigationMode {
|
||||
return false
|
||||
}
|
||||
|
||||
return slices.Contains(h.keys, msg.String())
|
||||
}
|
||||
|
||||
func (h upNavigationHandler) Handle(s state.State, msg tea.KeyMsg) tea.Cmd {
|
||||
s.MoveUp()
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user