keymap.go 934 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package filter
  2. import (
  3. "github.com/charmbracelet/bubbles/key"
  4. "github.com/remogatto/sugarfoam/components/group"
  5. "github.com/remogatto/sugarfoam/components/viewport"
  6. )
  7. type keyBindings struct {
  8. group *group.Model
  9. quit, enter key.Binding
  10. }
  11. func (k *keyBindings) ShortHelp() []key.Binding {
  12. keys := make([]key.Binding, 0)
  13. current := k.group.Current()
  14. switch item := current.(type) {
  15. case *viewport.Model:
  16. keys = append(
  17. keys,
  18. item.KeyMap.Up,
  19. item.KeyMap.Down,
  20. )
  21. }
  22. keys = append(
  23. keys,
  24. k.quit,
  25. )
  26. return keys
  27. }
  28. func (k keyBindings) FullHelp() [][]key.Binding {
  29. return [][]key.Binding{
  30. {
  31. k.quit,
  32. },
  33. }
  34. }
  35. func newBindings(g *group.Model) *keyBindings {
  36. return &keyBindings{
  37. group: g,
  38. quit: key.NewBinding(
  39. key.WithKeys("esc"), key.WithHelp("esc", "Quit app"),
  40. ),
  41. enter: key.NewBinding(
  42. key.WithKeys("enter"), key.WithHelp("enter", "Quit app and return the results"),
  43. ),
  44. }
  45. }