feat: implement item management handlers with corresponding tests
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"slices"
|
||||
|
||||
"github.com/StevanFreeborn/term-tier/internal/state"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
)
|
||||
|
||||
type selectItemHandler struct {
|
||||
keys []string
|
||||
description string
|
||||
}
|
||||
|
||||
func NewSelectItemHandler() KeyMsgHandler {
|
||||
return selectItemHandler{
|
||||
keys: []string{"enter", "space", " "},
|
||||
description: "Select item",
|
||||
}
|
||||
}
|
||||
|
||||
func (h selectItemHandler) KeysHandled() []string {
|
||||
return h.keys
|
||||
}
|
||||
|
||||
func (h selectItemHandler) Description() string {
|
||||
return h.description
|
||||
}
|
||||
|
||||
func (h selectItemHandler) Match(s state.State, msg tea.KeyMsg) bool {
|
||||
return s.Mode() == state.NavigationMode && slices.Contains(h.keys, msg.String())
|
||||
}
|
||||
|
||||
func (h selectItemHandler) Handle(s state.State, msg tea.KeyMsg) tea.Cmd {
|
||||
s.SelectItem()
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user