feat: implement item management handlers with corresponding tests
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"github.com/StevanFreeborn/term-tier/internal/state"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
)
|
||||
|
||||
type textInputHandler struct {
|
||||
keys []string
|
||||
description string
|
||||
}
|
||||
|
||||
func NewTextInputHandler() KeyMsgHandler {
|
||||
return textInputHandler{
|
||||
keys: []string{},
|
||||
description: "",
|
||||
}
|
||||
}
|
||||
|
||||
func (h textInputHandler) KeysHandled() []string {
|
||||
return h.keys
|
||||
}
|
||||
|
||||
func (h textInputHandler) Description() string {
|
||||
return h.description
|
||||
}
|
||||
|
||||
func (h textInputHandler) Match(s state.State, msg tea.KeyMsg) bool {
|
||||
return s.Mode() == state.InputMode
|
||||
}
|
||||
|
||||
func (h textInputHandler) Handle(s state.State, msg tea.KeyMsg) tea.Cmd {
|
||||
switch msg.String() {
|
||||
case "esc":
|
||||
s.ExitInputMode()
|
||||
return nil
|
||||
case "enter":
|
||||
return s.SubmitInput()
|
||||
default:
|
||||
return s.UpdateInput(msg)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user