37 lines
729 B
Go
37 lines
729 B
Go
package handlers
|
|||
|
|
|
||
|
|
import (
|
||
|
|
"slices"
|
||
|
|
|
||
|
|
"github.com/StevanFreeborn/term-tier/internal/state"
|
||
|
|
tea "github.com/charmbracelet/bubbletea"
|
||
|
|
)
|
||
|
|
|
||
|
|
type addItemHandler struct {
|
||
|
|
keys []string
|
||
|
|
description string
|
||
|
|
}
|
||
|
|
|
||
|
|
func NewAddItemHandler() KeyMsgHandler {
|
||
|
|
return addItemHandler{
|
||
|
|
keys: []string{"n"},
|
||
|
|
description: "Add new item",
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
func (h addItemHandler) KeysHandled() []string {
|
||
|
|
return h.keys
|
||
|
|
}
|
||
|
|
|
||
|
|
func (h addItemHandler) Description() string {
|
||
|
|
return h.description
|
||
|
|
}
|
||
|
|
|
||
|
|
func (h addItemHandler) Match(s state.State, msg tea.KeyMsg) bool {
|
||
|
|
return s.Mode() == state.NavigationMode && slices.Contains(h.keys, msg.String())
|
||
|
|
}
|
||
|
|
|
||
|
|
func (h addItemHandler) Handle(s state.State, msg tea.KeyMsg) tea.Cmd {
|
||
|
|
return s.AddItem()
|
||
|
|
}
|