command.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. package commands
  2. import (
  3. "github.com/charmbracelet/bubbles/v2/key"
  4. )
  5. // Command represents a user-triggerable action.
  6. type Command struct {
  7. // Name is the identifier used for slash commands (e.g., "new").
  8. Name string
  9. // Description is a short explanation of what the command does.
  10. Description string
  11. // KeyBinding is the keyboard shortcut to trigger this command.
  12. KeyBinding key.Binding
  13. }
  14. // Registry holds all the available commands.
  15. type Registry map[string]Command
  16. // ExecuteCommandMsg is a message sent when a command should be executed.
  17. type ExecuteCommandMsg struct {
  18. Name string
  19. }
  20. func NewCommandRegistry() Registry {
  21. return Registry{
  22. "help": {
  23. Name: "help",
  24. Description: "show help",
  25. KeyBinding: key.NewBinding(
  26. key.WithKeys("f1", "super+/", "super+h"),
  27. ),
  28. },
  29. "new": {
  30. Name: "new",
  31. Description: "new session",
  32. KeyBinding: key.NewBinding(
  33. key.WithKeys("f2", "super+n"),
  34. ),
  35. },
  36. "sessions": {
  37. Name: "sessions",
  38. Description: "switch session",
  39. KeyBinding: key.NewBinding(
  40. key.WithKeys("f3", "super+s"),
  41. ),
  42. },
  43. "model": {
  44. Name: "model",
  45. Description: "switch model",
  46. KeyBinding: key.NewBinding(
  47. key.WithKeys("f4", "super+m"),
  48. ),
  49. },
  50. "theme": {
  51. Name: "theme",
  52. Description: "switch theme",
  53. KeyBinding: key.NewBinding(
  54. key.WithKeys("f5", "super+t"),
  55. ),
  56. },
  57. "quit": {
  58. Name: "quit",
  59. Description: "quit",
  60. KeyBinding: key.NewBinding(
  61. key.WithKeys("f10", "ctrl+c", "super+q"),
  62. ),
  63. },
  64. }
  65. }