41 lines
729 B
Go
41 lines
729 B
Go
package handlers
|
|
|
|
import (
|
|
"slices"
|
|
|
|
"github.com/StevanFreeborn/term-tier/internal/state"
|
|
tea "github.com/charmbracelet/bubbletea"
|
|
)
|
|
|
|
type quitHandler struct {
|
|
keys []string
|
|
description string
|
|
}
|
|
|
|
func NewQuitHandler() KeyMsgHandler {
|
|
return quitHandler{
|
|
keys: []string{"ctrl+c", "q"},
|
|
description: "Quit",
|
|
}
|
|
}
|
|
|
|
func (h quitHandler) KeysHandled() []string {
|
|
return h.keys
|
|
}
|
|
|
|
func (h quitHandler) Description() string {
|
|
return h.description
|
|
}
|
|
|
|
func (h quitHandler) Match(s state.State, msg tea.KeyMsg) bool {
|
|
if s.Mode() != state.NavigationMode {
|
|
return false
|
|
}
|
|
|
|
return slices.Contains(h.keys, msg.String())
|
|
}
|
|
|
|
func (h quitHandler) Handle(s state.State, msg tea.KeyMsg) tea.Cmd {
|
|
return tea.Quit
|
|
}
|