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