43 lines
801 B
Go
43 lines
801 B
Go
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)
|
|
}
|
|
}
|